Skip to content

Commit 6396b7e

Browse files
steipetely85206559
andcommitted
fix(canvas): preserve literal arguments through Windows pnpm shims
Use the existing cmd.exe and CRT quoting contract, preserving empty arguments, carets, trailing backslashes and embedded quotes. Keep the unsafe-character guard and direct executable path while removing conditional quoting. The original serializer reproduced exact argv corruption on the native Windows regression. Co-authored-by: ben.li <[email protected]>
1 parent df3f016 commit 6396b7e

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

‎extensions/canvas/scripts/pnpm-runner.mjs‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,21 +106,21 @@ function isNodeRunnablePnpmExecPath(value) {
106106
return hasNodeShebang(value);
107107
}
108108

109-
function escapeForCmdExe(arg) {
110-
if (WINDOWS_UNSAFE_CMD_CHARS_RE.test(arg)) {
111-
throw new Error(`unsafe Windows cmd.exe argument detected: ${JSON.stringify(arg)}`);
112-
}
113-
const escaped = arg.replace(/\^/g, "^^");
114-
if (!escaped.includes(" ") && !escaped.includes('"')) {
115-
return escaped;
116-
}
117-
return `"${escaped.replace(/"/g, '""')}"`;
118-
}
119-
120109
function buildCmdExeCommandLine(command, args) {
121-
const escapedCommand = escapeForCmdExe(command);
122-
const commandLine = [escapedCommand, ...args.map(escapeForCmdExe)].join(" ");
123-
return escapedCommand.startsWith('"') ? `"${commandLine}"` : commandLine;
110+
const escaped = [command, ...args].map((arg) => {
111+
if (WINDOWS_UNSAFE_CMD_CHARS_RE.test(arg)) {
112+
throw new Error(`unsafe Windows cmd.exe argument detected: ${JSON.stringify(arg)}`);
113+
}
114+
// Quote through cmd and the CRT; consume backslash runs once to avoid quadratic scans.
115+
const quoted = arg
116+
.replace(/\\+/g, (backslashes, offset) => {
117+
const next = arg[offset + backslashes.length];
118+
return next === '"' || next === undefined ? backslashes.repeat(2) : backslashes;
119+
})
120+
.replace(/"/g, '""');
121+
return `"${quoted}"`;
122+
});
123+
return `"${escaped.join(" ")}"`;
124124
}
125125

126126
function windowsCmdSpec(command, args, comSpec) {

0 commit comments

Comments
 (0)