src: fix positional args in task runner · nodejs/node@d169d0f · GitHub
Skip to content

Commit d169d0f

Browse files
anonrigtargos
authored andcommitted
src: fix positional args in task runner
PR-URL: #52810 Fixes: #52740 Reviewed-By: Daniel Lemire <daniel@lemire.me> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 5055663 commit d169d0f

6 files changed

Lines changed: 109 additions & 44 deletions

File tree

src/node_task_runner.cc

Lines changed: 62 additions & 33 deletions

src/node_task_runner.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
namespace node {
1515
namespace task_runner {
1616

17+
using PositionalArgs = std::vector<std::string_view>;
18+
1719
// ProcessRunner is the class responsible for running a process.
1820
// A class instance is created for each process to be run.
1921
// The class is responsible for spawning the process and handling its exit.
@@ -22,7 +24,7 @@ class ProcessRunner {
2224
public:
2325
ProcessRunner(std::shared_ptr<InitializationResultImpl> result,
2426
std::string_view command_id,
25-
const std::optional<std::string>& positional_args);
27+
const PositionalArgs& positional_args);
2628
void Run();
2729
static void ExitCallback(uv_process_t* req,
2830
int64_t exit_status,
@@ -51,10 +53,9 @@ class ProcessRunner {
5153

5254
void RunTask(std::shared_ptr<InitializationResultImpl> result,
5355
std::string_view command_id,
54-
const std::optional<std::string>& positional_args);
55-
std::optional<std::string> GetPositionalArgs(
56-
const std::vector<std::string>& args);
57-
std::string EscapeShell(const std::string& command);
56+
const PositionalArgs& positional_args);
57+
PositionalArgs GetPositionalArgs(const std::vector<std::string>& args);
58+
std::string EscapeShell(const std::string_view command);
5859

5960
} // namespace task_runner
6061
} // namespace node

test/cctest/test_node_task_runner.cc

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@ class TaskRunnerTest : public EnvironmentTestFixture {};
99

1010
TEST_F(TaskRunnerTest, EscapeShell) {
1111
std::vector<std::pair<std::string, std::string>> expectations = {
12+
#ifdef _WIN32
13+
{"", "\"\""},
14+
{"test", "test"},
15+
{"test words", "\"test words\""},
16+
{"$1", "\"$1\""},
17+
{"\"$1\"", "\"\"\"$1\"\"\""},
18+
{"'$1'", "\"'$1'\""},
19+
{"\\$1", "\"\\$1\""},
20+
{"--arg=\"$1\"", "\"--arg=\"\"$1\"\"\""},
21+
{"--arg=node exec -c \"$1\"", "\"--arg=node exec -c \"\"$1\"\"\""},
22+
{"--arg=node exec -c '$1'", "\"--arg=node exec -c '$1'\""},
23+
{"'--arg=node exec -c \"$1\"'", "\"'--arg=node exec -c \"\"$1\"\"'\""}
24+
25+
#else
1226
{"", "''"},
1327
{"test", "test"},
1428
{"test words", "'test words'"},
@@ -19,7 +33,9 @@ TEST_F(TaskRunnerTest, EscapeShell) {
1933
{"--arg=\"$1\"", "'--arg=\"$1\"'"},
2034
{"--arg=node exec -c \"$1\"", "'--arg=node exec -c \"$1\"'"},
2135
{"--arg=node exec -c '$1'", "'--arg=node exec -c \\'$1\\''"},
22-
{"'--arg=node exec -c \"$1\"'", "'\\'--arg=node exec -c \"$1\"\\''"}};
36+
{"'--arg=node exec -c \"$1\"'", "'\\'--arg=node exec -c \"$1\"\\''"}
37+
#endif
38+
};
2339

2440
for (const auto& [input, expected] : expectations) {
2541
EXPECT_EQ(node::task_runner::EscapeShell(input), expected);

test/fixtures/run-script/node_modules/.bin/positional-args

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/run-script/node_modules/.bin/positional-args.bat

Lines changed: 15 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/parallel/test-node-run.js

Lines changed: 7 additions & 2 deletions

0 commit comments

Comments
 (0)