refactor: simplify pass (trekexecute)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
712a51591d
commit
c75ae2d3f5
4 changed files with 39 additions and 33 deletions
|
|
@ -272,30 +272,34 @@ const commandView = commandPositionView(deobfuscated.replace(/\x1B\[[0-9;]*m/g,
|
|||
// close early and an unquoted opener has nothing to expand, so it is skipped.
|
||||
// An opener with a non-blank line after it is blocked unless it is quoted
|
||||
// (<<'D', <<"D" or <<\D, whose body is not expanded) and exactly one line,
|
||||
// trimmed, equals the delimiter with every line after that one empty.
|
||||
// trimmed, equals the delimiter with every line after that one empty. A
|
||||
// command that never names the delimiter skips the whole check.
|
||||
const ARGS_DELIM = 'VOYAGE_ARGS_EOF_7F3C9E';
|
||||
const argsOpeners = command.matchAll(new RegExp(`<<-?\\s*(['"\\\\]?)${ARGS_DELIM}(['"]?)`, 'g'));
|
||||
const argsLines = command.split('\n');
|
||||
const argsClosing = argsLines.flatMap((l, i) => (l.trim() === ARGS_DELIM ? [i] : []));
|
||||
const closesOnceAtEnd = argsClosing.length === 1 &&
|
||||
argsLines.slice(argsClosing[0] + 1).every((line) => line.trim() === '');
|
||||
for (const argsOpener of argsOpeners) {
|
||||
const hasBody = command.slice(argsOpener.index).split('\n').slice(1).some((l) => l.trim() !== '');
|
||||
if (!hasBody) continue;
|
||||
const [, open, close] = argsOpener;
|
||||
const quoted = open === '\\' ? close === '' : open !== '' && close === open;
|
||||
if (!quoted || !closesOnceAtEnd) {
|
||||
const why = !quoted
|
||||
? `The heredoc that hands the arguments to the arg parser opens ${ARGS_DELIM} unquoted, so the shell would expand its body. ` +
|
||||
`Way forward: open it as <<'${ARGS_DELIM}'.`
|
||||
: `The arguments hold a line equal to the heredoc's closing line ${ARGS_DELIM}, or text follows that closing line, ` +
|
||||
'so the shell would run what follows as commands. Way forward: take that line out of the arguments and run the command again.';
|
||||
process.stderr.write(
|
||||
'[voyage] BLOCKED: args-heredoc-closed-early\n' +
|
||||
` Command: ${normalized.slice(0, 200)}${normalized.length > 200 ? '...' : ''}\n` +
|
||||
` ${why}\n`
|
||||
);
|
||||
process.exit(2);
|
||||
if (command.includes(ARGS_DELIM)) {
|
||||
const argsOpeners = command.matchAll(new RegExp(`<<-?\\s*(['"\\\\]?)${ARGS_DELIM}(['"]?)`, 'g'));
|
||||
const argsLines = command.split('\n');
|
||||
const argsClosing = argsLines.flatMap((l, i) => (l.trim() === ARGS_DELIM ? [i] : []));
|
||||
const closesOnceAtEnd = argsClosing.length === 1 &&
|
||||
argsLines.slice(argsClosing[0] + 1).every((line) => line.trim() === '');
|
||||
for (const argsOpener of argsOpeners) {
|
||||
// Some line after the opener's line is non-blank (\s is the set trim() strips).
|
||||
const hasBody = /\n\s*\S/.test(command.slice(argsOpener.index));
|
||||
if (!hasBody) continue;
|
||||
const [, open, close] = argsOpener;
|
||||
const quoted = open === '\\' ? close === '' : open !== '' && close === open;
|
||||
if (!quoted || !closesOnceAtEnd) {
|
||||
const why = !quoted
|
||||
? `The heredoc that hands the arguments to the arg parser opens ${ARGS_DELIM} unquoted, so the shell would expand its body. ` +
|
||||
`Way forward: open it as <<'${ARGS_DELIM}'.`
|
||||
: `The arguments hold a line equal to the heredoc's closing line ${ARGS_DELIM}, or text follows that closing line, ` +
|
||||
'so the shell would run what follows as commands. Way forward: take that line out of the arguments and run the command again.';
|
||||
process.stderr.write(
|
||||
'[voyage] BLOCKED: args-heredoc-closed-early\n' +
|
||||
` Command: ${normalized.slice(0, 200)}${normalized.length > 200 ? '...' : ''}\n` +
|
||||
` ${why}\n`
|
||||
);
|
||||
process.exit(2);
|
||||
}
|
||||
}
|
||||
}
|
||||
// END args-heredoc-closed-early
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue