Skip to content

Commit

Permalink
fix(container-command): Fix the issue of container command parsing fa…
Browse files Browse the repository at this point in the history
…ilure.
  • Loading branch information
ssongliu committed Nov 27, 2024
1 parent b8d8867 commit b555a15
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 41 deletions.
4 changes: 2 additions & 2 deletions frontend/src/lang/modules/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,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',
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/lang/modules/tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,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: '內存限製',
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/lang/modules/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,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: '内存限制',
Expand Down
64 changes: 30 additions & 34 deletions frontend/src/views/container/container/operate/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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}' `;
if (item.indexOf(' ') !== -1) {
itemCmd += `"${item.replaceAll('"', '\\"')}" `;
} else {
itemCmd += item + ' ';
}
}
dialogData.value.rowData.cmdStr = itemCmd ? itemCmd.substring(0, itemCmd.length - 1) : '';
dialogData.value.rowData.cmdStr = itemCmd.trimEnd();
let itemEntrypoint = '';
if (dialogData.value.rowData?.entrypoint) {
for (const item of dialogData.value.rowData.entrypoint) {
itemEntrypoint += `'${item}' `;
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');
Expand Down Expand Up @@ -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(/(?<!\\)"/g, '').replaceAll('\\"', '"'));
}
}
dialogData.value.rowData!.entrypoint = [];
if (dialogData.value.rowData?.entrypointStr) {
if (dialogData.value.rowData?.entrypointStr.indexOf(`'`) !== -1) {
let itemEntrypoint = dialogData.value.rowData!.entrypointStr.split(`'`);
for (const entry of itemEntrypoint) {
if (entry && entry !== ' ') {
dialogData.value.rowData!.entrypoint.push(entry);
}
}
} else {
let itemEntrypoint = dialogData.value.rowData!.entrypointStr.split(` `);
for (const entry of itemEntrypoint) {
dialogData.value.rowData!.entrypoint.push(entry);
}
let itemEntrypoint = splitWithQuotes(dialogData.value.rowData?.entrypointStr);
for (const item of itemEntrypoint) {
dialogData.value.rowData!.entrypoint.push(item.replace(/(?<!\\)"/g, '').replaceAll('\\"', '"'));
}
}
if (dialogData.value.rowData!.publishAllPorts) {
Expand Down Expand Up @@ -644,6 +629,17 @@ const isFromApp = (rowData: Container.ContainerHelper) => {
}
return false;
};
const splitWithQuotes = (str) => {
str = str.replace(/\\"/g, '<quota>');
const regex = /(?=(?:[^'"]|['"][^'"]*['"])*$)\s+/g;
let parts = str.split(regex).filter(Boolean);
let returnList = [];
for (const item of parts) {
returnList.push(item.replaceAll('<quota>', '\\"'));
}
return returnList;
};
defineExpose({
acceptParams,
});
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/setting/panel/api-interface/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,4 @@ const handleClose = () => {
defineExpose({
acceptParams,
});
</script>
</script>

0 comments on commit b555a15

Please sign in to comment.