diff --git a/frontend/src/views/container/container/operate/index.vue b/frontend/src/views/container/container/operate/index.vue index 6045c9cb0..aea136f94 100644 --- a/frontend/src/views/container/container/operate/index.vue +++ b/frontend/src/views/container/container/operate/index.vue @@ -361,7 +361,7 @@ const acceptParams = (params: DialogProps): void => { let itemCmd = ''; for (const item of dialogData.value.rowData.cmd) { if (item.indexOf(' ') !== -1) { - itemCmd += `"${item.replaceAll('"', '\\"')}" `; + itemCmd += `"${escapeQuotes(item)}" `; } else { itemCmd += item + ' '; } @@ -370,7 +370,7 @@ const acceptParams = (params: DialogProps): void => { let itemEntrypoint = ''; for (const item of dialogData.value.rowData.entrypoint) { if (item.indexOf(' ') !== -1) { - itemEntrypoint += `"${item.replaceAll('"', '\\"')}" `; + itemEntrypoint += `"${escapeQuotes(item)}" `; } else { itemEntrypoint += item + ' '; } @@ -504,14 +504,14 @@ const submit = async () => { } dialogData.value.rowData!.cmd = []; if (dialogData.value.rowData?.cmdStr) { - let itemCmd = splitWithQuotes(dialogData.value.rowData?.cmdStr); + let itemCmd = splitStringIgnoringQuotes(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('', '\\"')); +const escapeQuotes = (input) => { + return input.replace(/(? { + input = input.replace(/\\"/g, ''); + const regex = /"([^"]*)"|(\S+)/g; + const result = []; + let match; + + while ((match = regex.exec(input)) !== null) { + if (match[1]) { + result.push(match[1].replaceAll('', '\\"')); + } else if (match[2]) { + result.push(match[2].replaceAll('', '\\"')); + } } - return returnList; + + return result; }; defineExpose({ acceptParams,