Skip to content

Commit

Permalink
fix: remove empty arguments from launcher (#1650)
Browse files Browse the repository at this point in the history
* fix: remove empty arguments from launcher

* fix: remove duplication and add tests

* fix: remove accidental commit of vscode settings

* fix: remove unecessary change
  • Loading branch information
purkhusid authored Feb 18, 2020
1 parent 25600ea commit aa3cd6c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/node/launcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions internal/node/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
10 changes: 10 additions & 0 deletions internal/node/test/empty_args_fail.js
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit aa3cd6c

Please sign in to comment.