fix(container): Fix the issue of container command parsing failure (#7307)

pull/7311/head
ssongliu 2024-12-10 15:55:39 +08:00 committed by GitHub
parent b7702daea3
commit 9ac9f76a1d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 22 additions and 12 deletions

View File

@ -361,7 +361,7 @@ const acceptParams = (params: DialogProps): void => {
let itemCmd = ''; let itemCmd = '';
for (const item of dialogData.value.rowData.cmd) { for (const item of dialogData.value.rowData.cmd) {
if (item.indexOf(' ') !== -1) { if (item.indexOf(' ') !== -1) {
itemCmd += `"${item.replaceAll('"', '\\"')}" `; itemCmd += `"${escapeQuotes(item)}" `;
} else { } else {
itemCmd += item + ' '; itemCmd += item + ' ';
} }
@ -370,7 +370,7 @@ const acceptParams = (params: DialogProps): void => {
let itemEntrypoint = ''; let itemEntrypoint = '';
for (const item of dialogData.value.rowData.entrypoint) { for (const item of dialogData.value.rowData.entrypoint) {
if (item.indexOf(' ') !== -1) { if (item.indexOf(' ') !== -1) {
itemEntrypoint += `"${item.replaceAll('"', '\\"')}" `; itemEntrypoint += `"${escapeQuotes(item)}" `;
} else { } else {
itemEntrypoint += item + ' '; itemEntrypoint += item + ' ';
} }
@ -504,14 +504,14 @@ const submit = async () => {
} }
dialogData.value.rowData!.cmd = []; dialogData.value.rowData!.cmd = [];
if (dialogData.value.rowData?.cmdStr) { if (dialogData.value.rowData?.cmdStr) {
let itemCmd = splitWithQuotes(dialogData.value.rowData?.cmdStr); let itemCmd = splitStringIgnoringQuotes(dialogData.value.rowData?.cmdStr);
for (const item of itemCmd) { for (const item of itemCmd) {
dialogData.value.rowData!.cmd.push(item.replace(/(?<!\\)"/g, '').replaceAll('\\"', '"')); dialogData.value.rowData!.cmd.push(item.replace(/(?<!\\)"/g, '').replaceAll('\\"', '"'));
} }
} }
dialogData.value.rowData!.entrypoint = []; dialogData.value.rowData!.entrypoint = [];
if (dialogData.value.rowData?.entrypointStr) { if (dialogData.value.rowData?.entrypointStr) {
let itemEntrypoint = splitWithQuotes(dialogData.value.rowData?.entrypointStr); let itemEntrypoint = splitStringIgnoringQuotes(dialogData.value.rowData?.entrypointStr);
for (const item of itemEntrypoint) { for (const item of itemEntrypoint) {
dialogData.value.rowData!.entrypoint.push(item.replace(/(?<!\\)"/g, '').replaceAll('\\"', '"')); dialogData.value.rowData!.entrypoint.push(item.replace(/(?<!\\)"/g, '').replaceAll('\\"', '"'));
} }
@ -630,15 +630,25 @@ const isFromApp = (rowData: Container.ContainerHelper) => {
return false; return false;
}; };
const splitWithQuotes = (str) => { const escapeQuotes = (input) => {
str = str.replace(/\\"/g, '<quota>'); return input.replace(/(?<!\\)"/g, '\\"');
const regex = /(?=(?:[^'"]|['"][^'"]*['"])*$)\s+/g; };
let parts = str.split(regex).filter(Boolean);
let returnList = []; const splitStringIgnoringQuotes = (input) => {
for (const item of parts) { input = input.replace(/\\"/g, '<quota>');
returnList.push(item.replaceAll('<quota>', '\\"')); const regex = /"([^"]*)"|(\S+)/g;
const result = [];
let match;
while ((match = regex.exec(input)) !== null) {
if (match[1]) {
result.push(match[1].replaceAll('<quota>', '\\"'));
} else if (match[2]) {
result.push(match[2].replaceAll('<quota>', '\\"'));
}
} }
return returnList;
return result;
}; };
defineExpose({ defineExpose({
acceptParams, acceptParams,