diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index ed2417f29..9306b95da 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -678,8 +678,8 @@ const message = { containerExample: '80 or 80-88', exposePort: 'Expose port', exposeAll: 'Expose all', - cmdHelper: "e.g. 'nginx' '-g' 'daemon off;' OR nginx -g daemon off;", - entrypointHelper: 'e.g. /bin/sh -c', + cmdHelper: 'e.g. nginx -g "daemon off;"', + entrypointHelper: 'e.g. docker-entrypoint.sh', autoRemove: 'Auto remove', cpuQuota: 'NacosCPU', memoryLimit: 'Memory', diff --git a/frontend/src/lang/modules/tw.ts b/frontend/src/lang/modules/tw.ts index 66b66bbb8..b0726afbe 100644 --- a/frontend/src/lang/modules/tw.ts +++ b/frontend/src/lang/modules/tw.ts @@ -652,8 +652,8 @@ const message = { containerExample: '80 或者 80-88', exposePort: '暴露端口', exposeAll: '暴露所有', - cmdHelper: "例: 'nginx' '-g' 'daemon off;' 或 nginx -g daemon off;", - entrypointHelper: '例: /bin/sh -c', + cmdHelper: '例: nginx -g "daemon off;"', + entrypointHelper: '例: docker-entrypoint.sh', autoRemove: '容器退出後自動刪除容器', cpuQuota: 'CPU 限製', memoryLimit: '內存限製', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index df2474c51..2eeda99ac 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -654,8 +654,8 @@ const message = { containerExample: '80 或者 80-88', exposePort: '暴露端口', exposeAll: '暴露所有', - cmdHelper: "例: 'nginx' '-g' 'daemon off;' 或者 nginx -g daemon off;", - entrypointHelper: '例: /bin/sh -c', + cmdHelper: '例: nginx -g "daemon off;"', + entrypointHelper: '例: docker-entrypoint.sh', autoRemove: '容器退出后自动删除容器', cpuQuota: 'CPU 限制', memoryLimit: '内存限制', diff --git a/frontend/src/views/container/container/operate/index.vue b/frontend/src/views/container/container/operate/index.vue index 4ddda0a0c..8fa60ffe0 100644 --- a/frontend/src/views/container/container/operate/index.vue +++ b/frontend/src/views/container/container/operate/index.vue @@ -357,23 +357,26 @@ const acceptParams = (params: DialogProps): void => { title.value = i18n.global.t('container.' + dialogData.value.title); if (params.title === 'edit') { dialogData.value.rowData.memory = Number(dialogData.value.rowData.memory.toFixed(2)); - dialogData.value.rowData.cmd = dialogData.value.rowData.cmd || []; + let itemCmd = ''; for (const item of dialogData.value.rowData.cmd) { - itemCmd += `'${item}' `; - } - dialogData.value.rowData.cmdStr = itemCmd ? itemCmd.substring(0, itemCmd.length - 1) : ''; - - let itemEntrypoint = ''; - if (dialogData.value.rowData?.entrypoint) { - for (const item of dialogData.value.rowData.entrypoint) { - itemEntrypoint += `'${item}' `; + if (item.indexOf(' ') !== -1) { + itemCmd += `"${item.replaceAll('"', '\\"')}" `; + } else { + itemCmd += item + ' '; } } + dialogData.value.rowData.cmdStr = itemCmd.trimEnd(); + let itemEntrypoint = ''; + for (const item of dialogData.value.rowData.entrypoint) { + if (item.indexOf(' ') !== -1) { + itemEntrypoint += `"${item.replaceAll('"', '\\"')}" `; + } else { + itemEntrypoint += item + ' '; + } + } + dialogData.value.rowData.entrypointStr = itemEntrypoint.trimEnd(); - dialogData.value.rowData.entrypointStr = itemEntrypoint - ? itemEntrypoint.substring(0, itemEntrypoint.length - 1) - : ''; dialogData.value.rowData.labels = dialogData.value.rowData.labels || []; dialogData.value.rowData.env = dialogData.value.rowData.env || []; dialogData.value.rowData.labelsStr = dialogData.value.rowData.labels.join('\n'); @@ -501,34 +504,16 @@ const submit = async () => { } dialogData.value.rowData!.cmd = []; if (dialogData.value.rowData?.cmdStr) { - if (dialogData.value.rowData?.cmdStr.indexOf(`'`) !== -1) { - let itemCmd = dialogData.value.rowData!.cmdStr.split(`'`); - for (const cmd of itemCmd) { - if (cmd && cmd !== ' ') { - dialogData.value.rowData!.cmd.push(cmd); - } - } - } else { - let itemCmd = dialogData.value.rowData!.cmdStr.split(` `); - for (const cmd of itemCmd) { - dialogData.value.rowData!.cmd.push(cmd); - } + let itemCmd = splitWithQuotes(dialogData.value.rowData?.cmdStr); + for (const item of itemCmd) { + dialogData.value.rowData!.cmd.push(item.replace(/(? { } return false; }; + +const splitWithQuotes = (str) => { + str = str.replace(/\\"/g, ''); + const regex = /(?=(?:[^'"]|['"][^'"]*['"])*$)\s+/g; + let parts = str.split(regex).filter(Boolean); + let returnList = []; + for (const item of parts) { + returnList.push(item.replaceAll('', '\\"')); + } + return returnList; +}; defineExpose({ acceptParams, });