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 = '';
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(/(?<!\\)"/g, '').replaceAll('\\"', '"'));
}
}
dialogData.value.rowData!.entrypoint = [];
if (dialogData.value.rowData?.entrypointStr) {
let itemEntrypoint = splitWithQuotes(dialogData.value.rowData?.entrypointStr);
let itemEntrypoint = splitStringIgnoringQuotes(dialogData.value.rowData?.entrypointStr);
for (const item of itemEntrypoint) {
dialogData.value.rowData!.entrypoint.push(item.replace(/(?<!\\)"/g, '').replaceAll('\\"', '"'));
}
@ -630,15 +630,25 @@ 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>', '\\"'));
const escapeQuotes = (input) => {
return input.replace(/(?<!\\)"/g, '\\"');
};
const splitStringIgnoringQuotes = (input) => {
input = input.replace(/\\"/g, '<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({
acceptParams,