mirror of
https://github.com/whyour/qinglong.git
synced 2026-12-01 01:39:52 +08:00
fix: handle quoted script paths and stabilize lifecycle tests
Parse literal shell arguments for script navigation and pass preloader hook paths as process arguments. Use the actual task entry for ts-node hooks. Isolate unused history dependencies in the spawn-failure test while preserving its 3-second timeout and real child-process assertions. Add regression coverage for quoting, hooks and navigation safety. Validated formatting, 240 dev regressions, 45 preload-related regressions, 19 CLI checks, 10 lifecycle repeat runs, and both image variants with 20 execution and navigation scenarios.
This commit is contained in:
1 parent
c5458596c8
commit
188f8805cb
6 files changed
+224
-39
No files matched your search
+45
-2
@@ -308,12 +308,55 @@ export function logEnded(log: string): boolean {
|
||||
export function getCommandScript(
|
||||
command: string,
|
||||
): [string, string] | string | undefined {
|
||||
const cmd = command.split(' ') as string[];
|
||||
// Read shell arguments without evaluating substitutions or expanding paths.
|
||||
// Quoted and unquoted fragments can form one argument (task 'my dir'/a.js).
|
||||
const cmd: string[] = [];
|
||||
const raw: string[] = [];
|
||||
let value = '',
|
||||
source = '',
|
||||
quote = '',
|
||||
active = false;
|
||||
for (let i = 0; i < command.length; i++) {
|
||||
const c = command[i];
|
||||
if (c === '\n' || c === '\r') return;
|
||||
if (!quote && /\s/.test(c)) {
|
||||
if (active) {
|
||||
cmd.push(value);
|
||||
raw.push(source);
|
||||
}
|
||||
value = source = '';
|
||||
active = false;
|
||||
continue;
|
||||
}
|
||||
source += c;
|
||||
active = true;
|
||||
if (c === quote) {
|
||||
quote = '';
|
||||
} else if (!quote && (c === "'" || c === '"')) {
|
||||
quote = c;
|
||||
} else if (c === '\\' && quote !== "'") {
|
||||
const next = command[++i];
|
||||
if (next === undefined || /[\r\n]/.test(next)) return;
|
||||
source += next;
|
||||
if (quote === '"' && !/[$`"\\]/.test(next)) value += '\\';
|
||||
value += next;
|
||||
} else {
|
||||
value += c;
|
||||
}
|
||||
}
|
||||
if (quote) return;
|
||||
if (active) {
|
||||
cmd.push(value);
|
||||
raw.push(source);
|
||||
}
|
||||
if (cmd[1] === 'repo' || cmd[1] === 'raw') {
|
||||
// Keep ambiguous escaped URLs out of browser navigation, even if removing
|
||||
// the shell escape would turn them into a syntactically valid web URL.
|
||||
if (raw[2]?.includes('\\')) return;
|
||||
return cmd[2];
|
||||
}
|
||||
let scriptsPart = cmd.find((x) =>
|
||||
['.js', '.ts', '.sh', '.py'].some((y) => x.endsWith(y)),
|
||||
['.js', '.mjs', '.cjs', '.ts', '.sh', '.py'].some((y) => x.endsWith(y)),
|
||||
);
|
||||
if (!scriptsPart) return;
|
||||
const scriptDir = `${window.__ENV__QL_DIR}/data/scripts`;
|
||||
|
||||
Reference in new issue
Block a user