aboutsummaryrefslogtreecommitdiff
path: root/plugin
diff options
context:
space:
mode:
Diffstat (limited to 'plugin')
-rw-r--r--plugin/src/runner.js4
-rw-r--r--plugin/test/runner.test.js2
2 files changed, 5 insertions, 1 deletions
diff --git a/plugin/src/runner.js b/plugin/src/runner.js
index a327c58..7b7c1e0 100644
--- a/plugin/src/runner.js
+++ b/plugin/src/runner.js
@@ -5,7 +5,9 @@ const path = require('node:path');
function quote(value, shell) {
if (/[\r\n\0]/.test(value)) throw new Error('Run paths must not contain line breaks or NUL characters.');
if (shell === 'cmd') return `"${value}"`;
- return "'" + value.replace(/'/g, shell === 'powershell' ? "''" : "'\\''") + "'";
+ // PowerShell also ends single-quoted strings at the typographic quotes U+2018 to U+201B.
+ if (shell === 'powershell') return "'" + value.replace(/['\u2018-\u201B]/g, m => m + m) + "'";
+ return "'" + value.replace(/'/g, "'\\''") + "'";
}
function buildRunCommand(compiler, file, cwd, shell) {
diff --git a/plugin/test/runner.test.js b/plugin/test/runner.test.js
index a22d103..c795b85 100644
--- a/plugin/test/runner.test.js
+++ b/plugin/test/runner.test.js
@@ -12,6 +12,8 @@ test('commands quote paths and only run after changing directory', () => {
'cd /d "D:\\My Files" && "C:\\My Tools\\cpsc.exe" "D:\\My Files\\test.cps" -r');
assert.equal(buildRunCommand('C:\\My Tools\\cpsc.exe', "D:\\Pat's Files\\test.cps", "D:\\Pat's Files", 'powershell'),
"Set-Location -LiteralPath 'D:\\Pat''s Files'; if ($?) { & 'C:\\My Tools\\cpsc.exe' 'D:\\Pat''s Files\\test.cps' -r }");
+ assert.equal(buildRunCommand('cpsc', 'Pat\u2019s \u2018x\u201B.cps', '.', 'powershell'),
+ "Set-Location -LiteralPath '.'; if ($?) { & 'cpsc' 'Pat\u2019\u2019s \u2018\u2018x\u201B\u201B.cps' -r }");
assert.throws(() => buildRunCommand('cpsc\nother', 'test.cps', '.', 'posix'), /line breaks/);
if (process.platform !== 'win32') {
const file = "/tmp/Pat's file $(echo unexpected) `echo unexpected`.cps";