From c503e184b26fc48c71ecd0c6d4cdb7c907ac35c6 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Mon, 26 Nov 2018 19:40:09 +0900 Subject: [PATCH] cli: 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 --- 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); + }); + } }