Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/node_task_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ std::string EscapeShell(const std::string_view input) {
escaped = std::regex_replace(escaped, leadingQuotePairs, "");
escaped = std::regex_replace(escaped, tripleSingleQuote, "\\\"");
#else
// Replace single quotes("'") with "\\'" and wrap the result
// Replace single quotes("'") with `'"'"'` and wrap the result
// in single quotes.
std::string escaped =
std::regex_replace(std::string(input), std::regex("'"), "\\'");
std::regex_replace(std::string(input), std::regex("'"), "'\"'\"'");
escaped = "'" + escaped + "'";
// Remove excessive quote pairs and handle edge cases
static const std::regex tripleSingleQuote("\\\\'''");
Expand Down
6 changes: 3 additions & 3 deletions test/cctest/test_node_task_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ TEST_F(TaskRunnerTest, EscapeShell) {
{"test words", "'test words'"},
{"$1", "'$1'"},
{"\"$1\"", "'\"$1\"'"},
{"'$1'", "'\\'$1\\''"},
{"'$1'", "\"'\"'$1'\"'\"''"},
{"\\$1", "'\\$1'"},
{"--arg=\"$1\"", "'--arg=\"$1\"'"},
{"--arg=node exec -c \"$1\"", "'--arg=node exec -c \"$1\"'"},
{"--arg=node exec -c '$1'", "'--arg=node exec -c \\'$1\\''"},
{"'--arg=node exec -c \"$1\"'", "'\\'--arg=node exec -c \"$1\"\\''"}
{"--arg=node exec -c '$1'", "'--arg=node exec -c '\"'\"'$1'\"'\"''"},
{"'--arg=node exec -c \"$1\"'", "\"'\"'--arg=node exec -c \"$1\"'\"'\"''"}
#endif
};

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/run-script/node_modules/.bin/positional-args

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions test/parallel/test-node-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,15 @@ describe('node --run [command]', () => {
it('appends positional arguments', async () => {
const child = await common.spawnPromisified(
process.execPath,
[ '--run', `positional-args${envSuffix}`, '--', '--help "hello world test"', 'A', 'B', 'C'],
[ '--run', `positional-args${envSuffix}`, '--', '--help "hello world test"', 'A', 'B', 'C', 'I think therefore I\'m'],
{ cwd: fixtures.path('run-script') },
);
if (common.isWindows) {
assert.match(child.stdout, /Arguments: '--help ""hello world test"" A B C'/);
assert.match(child.stdout, /Arguments: '--help ""hello world test"" A B C "I think therefore I'm"'/);
} else {
assert.match(child.stdout, /Arguments: '--help "hello world test" A B C'/);
assert.match(child.stdout, /Arguments: '--help "hello world test" A B C I think therefore I'm'/);
}
assert.match(child.stdout, /The total number of arguments are: 4/);
assert.match(child.stdout, /The total number of arguments is: 5/);
assert.strictEqual(child.stderr, '');
assert.strictEqual(child.code, 0);
});
Expand Down
Loading