mirror of https://github.com/1Panel-dev/1Panel
fix(container): Fix the issue of container command parsing failure (#7307)
parent
b7702daea3
commit
9ac9f76a1d
|
@ -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,
|
||||||
|
|
Loading…
Reference in New Issue