From aa3cd6c0bb26c09be58252652b9e8b4ff81ea06e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=2E=20Purkh=C3=BAs?= Date: Tue, 18 Feb 2020 19:00:56 +0000 Subject: [PATCH] fix: remove empty arguments from launcher (#1650) * fix: remove empty arguments from launcher * fix: remove duplication and add tests * fix: remove accidental commit of vscode settings * fix: remove unecessary change --- internal/node/launcher.sh | 4 ++-- internal/node/test/BUILD.bazel | 7 +++++++ internal/node/test/empty_args_fail.js | 10 ++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 internal/node/test/empty_args_fail.js diff --git a/internal/node/launcher.sh b/internal/node/launcher.sh index 61397e0feb..2a1992c446 100644 --- a/internal/node/launcher.sh +++ b/internal/node/launcher.sh @@ -224,12 +224,12 @@ if [ "${EXPECTED_EXIT_CODE}" -eq "0" ]; then # handled by the node process. # If we had merely forked a child process here, we'd be responsible # for forwarding those OS interactions. - exec "${node}" "${LAUNCHER_NODE_OPTIONS[@]:-}" "${USER_NODE_OPTIONS[@]:-}" "${MAIN}" "${ARGS[@]:-}" + exec "${node}" "${LAUNCHER_NODE_OPTIONS[@]:-}" "${USER_NODE_OPTIONS[@]:-}" "${MAIN}" ${ARGS[@]+"${ARGS[@]}"} # exec terminates execution of this shell script, nothing later will run. fi set +e -"${node}" "${LAUNCHER_NODE_OPTIONS[@]:-}" "${USER_NODE_OPTIONS[@]:-}" "${MAIN}" "${ARGS[@]:-}" +"${node}" "${LAUNCHER_NODE_OPTIONS[@]:-}" "${USER_NODE_OPTIONS[@]:-}" "${MAIN}" ${ARGS[@]+"${ARGS[@]}"} RESULT="$?" set -e diff --git a/internal/node/test/BUILD.bazel b/internal/node/test/BUILD.bazel index 6f32599d88..897a3cbeef 100644 --- a/internal/node/test/BUILD.bazel +++ b/internal/node/test/BUILD.bazel @@ -335,3 +335,10 @@ nodejs_test( expected_exit_code = 55, templated_args = ["--node_options=--require=$(rlocation $(location :bootstrap_with_patch.js))"], ) + +nodejs_test( + name = "binary_with_no_arguments", + data = ["empty_args_fail.js"], + entry_point = "empty_args_fail.js", + expected_exit_code = 0, +) diff --git a/internal/node/test/empty_args_fail.js b/internal/node/test/empty_args_fail.js new file mode 100644 index 0000000000..6f4b8c0f5a --- /dev/null +++ b/internal/node/test/empty_args_fail.js @@ -0,0 +1,10 @@ +// Used to test that there is no empty argument +// sent to the program when the argument list is empty. +// Some programs do not handle empty arguments gracefully + +var theArgs = process.argv.slice(2); + +if (theArgs.length != 0) { + // Non-zero exit code if the argument list is not empty + process.exit(42) +}