From 726d0a80bd858722dac3b1ae5f809cf1856b44ef Mon Sep 17 00:00:00 2001 From: seungwonme Date: Sun, 15 Nov 2026 16:25:50 +0900 Subject: [PATCH] fix(setup): double typographic single quotes in PowerShell string quoting --- src/builder.js | 4 +++- tests/windows.test.js | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/builder.js b/src/builder.js index 27956db..a4965de 100644 --- a/src/builder.js +++ b/src/builder.js @@ -298,8 +298,10 @@ function sh(value) { return `'${String(value).replace(/'/g, `'\\''`)}'`; } +// PowerShell treats ASCII ' and the typographic quotes U+2018, U+2019, U+201A, U+201B as single-quote delimiters. +// Doubling any of them inside a single-quoted string yields the literal character. function ps(value) { - return `'${String(value).replace(/'/g, "''")}'`; + return `'${String(value).replace(/['\u2018\u2019\u201A\u201B]/g, "$&$&")}'`; } function boolSetting(settings, key) { diff --git a/tests/windows.test.js b/tests/windows.test.js index d07d76b..5627767 100644 --- a/tests/windows.test.js +++ b/tests/windows.test.js @@ -128,6 +128,18 @@ assert.match(commandDetector, /--version/); assert.match(pythonBody, /-DeferFailure/); assert.match(pythonBody, /if \(-not \$pythonOk\) \{ Fail 'Python' \}/); +// ps() must double every character PowerShell accepts as a single-quote delimiter, or a value can break out of its string. +{ + const payload = "a\u2019;calc;\u2019 b\u2018c\u201Ad\u201Be'f"; + const quoted = buildWindowsScript(resolveSelection(new Set(["git", "git-config"]), "win"), { gitName: payload, gitEmail: "x@example.com" }); + assert.match(quoted, /Set-GitDefaults -Name 'a\u2019\u2019;calc;\u2019\u2019 b\u2018\u2018c\u201A\u201Ad\u201B\u201Be''f' -Email 'x@example\.com'/); + for (const quote of ["\u2018", "\u2019", "\u201A", "\u201B", "'"]) { + const line = buildWindowsScript(resolveSelection(new Set(["git", "git-config"]), "win"), { gitName: `x${quote}y`, gitEmail: "e@example.com" }) + .split("\r\n").find((l) => l.startsWith("Set-GitDefaults ")); + assert.equal(line, `Set-GitDefaults -Name 'x${quote}${quote}y' -Email 'e@example.com'`); + } +} + const claudeTelemetry = resolveSelection(new Set(["claude-code-telemetry"]), "win"); const claudeTelemetryScript = buildWindowsScript(claudeTelemetry, { ...settings,