Skip to content

Commit 6cb56f1

Browse files
committed
playground: don't path-resolve sed script args
resolvePath() normalizes path segments and drops trailing empty components, so a sed script like 's/world/there/' was rewritten to 's/world/there', losing the closing delimiter and producing 'unterminated substitute replacement'. Skip resolvePath for sed's script argument(s) (the first non-option arg, or args after -e/-f).
1 parent a227501 commit 6cb56f1

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

static/js/wasm-terminal.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,10 +638,30 @@ async function executeCommandLine(line) {
638638
}
639639

640640
try {
641+
// sed's script argument is a program, not a path — it must NOT go through
642+
// resolvePath, which normalizes path segments and would strip a trailing
643+
// delimiter (e.g. `s/world/there/` -> `s/world/there`, breaking the `s`
644+
// command). Collect the indices of any sed script arguments to skip.
645+
const sedScriptIndices = new Set();
646+
if (cmd === "sed") {
647+
let scriptFromFlag = false;
648+
for (let i = 1; i < args.length; i++) {
649+
const a = args[i];
650+
if (a === "-e" || a === "-f") { sedScriptIndices.add(i + 1); scriptFromFlag = true; i++; continue; }
651+
if (a.startsWith("-e") || a.startsWith("-f")) { scriptFromFlag = true; } // combined form, e.g. -e's/a/b/'
652+
}
653+
// Without -e/-f, the script is the first non-option argument.
654+
if (!scriptFromFlag) {
655+
for (let i = 1; i < args.length; i++) {
656+
if (!args[i].startsWith("-")) { sedScriptIndices.add(i); break; }
657+
}
658+
}
659+
}
641660
// Resolve relative paths using the virtual cwd
642661
const resolvedArgs = args.map((arg, i) => {
643662
if (i === 0) return arg; // command name
644663
if (arg.startsWith("-")) return arg; // flag
664+
if (sedScriptIndices.has(i)) return arg; // sed script, not a path
645665
return resolvePath(arg);
646666
});
647667
// If the command takes a default path (like ls) and no path args

0 commit comments

Comments
 (0)