From effe30777b6744272ea2d08989321f51e98b29cf Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Mon, 26 Nov 2018 19:40:09 +0900 Subject: [PATCH] process: fix omitting `--` from `process.execArgv` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This was essentially a typo that went unnoticed because we didn’t have tests for this particular situation. Fixes: https://github.com/nodejs/node/issues/24647 PR-URL: https://github.com/nodejs/node/pull/24654 Reviewed-By: Richard Lau Reviewed-By: Colin Ihrig Reviewed-By: Luigi Pinca Reviewed-By: Gus Caplan Reviewed-By: Franziska Hinkelmann --- src/node_options-inl.h | 2 +- test/parallel/test-process-exec-argv.js | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/node_options-inl.h b/src/node_options-inl.h index 277121036e519d..468368ac84f630 100644 --- a/src/node_options-inl.h +++ b/src/node_options-inl.h @@ -253,7 +253,7 @@ struct ArgsInfo { // on the command line (i.e. not generated through alias expansion). // '--' is a special case here since its purpose is to end `exec_argv`, // which is why we do not include it. - if (exec_args != nullptr && first() != "--") + if (exec_args != nullptr && ret != "--") exec_args->push_back(ret); underlying->erase(underlying->begin() + 1); } else { diff --git a/test/parallel/test-process-exec-argv.js b/test/parallel/test-process-exec-argv.js index fec5699933d6f4..578ee7b5d1a5e3 100644 --- a/test/parallel/test-process-exec-argv.js +++ b/test/parallel/test-process-exec-argv.js @@ -27,16 +27,19 @@ const spawn = require('child_process').spawn; if (process.argv[2] === 'child') { process.stdout.write(JSON.stringify(process.execArgv)); } else { - const execArgv = ['--stack-size=256']; - const args = [__filename, 'child', 'arg0']; - const child = spawn(process.execPath, execArgv.concat(args)); - let out = ''; + for (const extra of [ [], [ '--' ] ]) { + const execArgv = ['--stack-size=256']; + const args = [__filename, 'child', 'arg0']; + const child = spawn(process.execPath, [...execArgv, ...extra, ...args]); + let out = ''; - child.stdout.on('data', function(chunk) { - out += chunk; - }); + child.stdout.setEncoding('utf8'); + child.stdout.on('data', function(chunk) { + out += chunk; + }); - child.on('close', function() { - assert.deepStrictEqual(JSON.parse(out), execArgv); - }); + child.on('close', function() { + assert.deepStrictEqual(JSON.parse(out), execArgv); + }); + } }