Skip to content

Commit ffa3ffb

Browse files
authored
fix(builtin): properly quote env vars passed to nodejs_binary (#3553)
1 parent e743399 commit ffa3ffb

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

internal/node/node.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def _nodejs_binary_impl(ctx, data = [], runfiles = [], expanded_args = []):
204204

205205
# Add all env vars from the ctx attr
206206
for [key, value] in ctx.attr.env.items():
207-
env_vars += "export %s=%s\n" % (key, ctx.expand_make_variables("env", expand_location_into_runfiles(ctx, value, data), {}))
207+
env_vars += "export %s=\"%s\"\n" % (key, ctx.expand_make_variables("env", expand_location_into_runfiles(ctx, value, data), {}))
208208

209209
# While we can derive the workspace from the pwd when running locally
210210
# because it is in the execroot path `execroot/my_wksp`, on RBE the

internal/node/test/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ nodejs_binary(
410410
env = {
411411
"LOC": "$(location :dump_build_env.js)",
412412
"SOME_TEST_ENV": "$(SOME_TEST_ENV)",
413+
"BACKSLASHES": "C:\\some path\\on\\windows.exe",
413414
},
414415
)
415416

internal/node/test/env.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,9 @@ describe('launcher.sh environment', function() {
123123
const env = require(runfiles.resolvePackageRelative('dump_build_env_attr.json'));
124124
expect(env['SOME_TEST_ENV']).toBe('some_value')
125125
});
126+
127+
it('should correctly pass environment variables with backslashes', function() {
128+
const env = require(runfiles.resolvePackageRelative('dump_build_env_attr.json'));
129+
expect(env['BACKSLASHES']).toBe('C:\\some path\\on\\windows.exe');
130+
});
126131
});

0 commit comments

Comments
 (0)