Fix test failures on darwin caused by non-GNU awk

Use printf("...%c...", 0) instead of printf("...\0...") to inject \0.
This commit is contained in:
Dean Brettle
2018-07-04 22:09:27 -07:00
parent 60a48af9be
commit 267b210c40
2 changed files with 5 additions and 4 deletions

View File

@@ -224,7 +224,7 @@ describe('updateProcessEnv(launchEnv)', function () {
await updateProcessEnv(process.env)
expect(spawn.calls.length).toBe(1)
expect(spawn.calls[0].command).toBe('/my/custom/bash')
expect(spawn.calls[0].args).toEqual(['-ilc', 'command awk \'BEGIN{for(v in ENVIRON) printf("%s=%s\\0",v,ENVIRON[v])}\''])
expect(spawn.calls[0].args).toEqual(['-ilc', 'command awk \'BEGIN{for(v in ENVIRON) printf("%s=%s%c", v, ENVIRON[v], 0)}\''])
expect(process.env).toEqual({
FOO: 'BAR=BAZ=QUUX',
'MULTILINE\nNAME': 'multiline\nvalue',
@@ -247,7 +247,7 @@ describe('updateProcessEnv(launchEnv)', function () {
await updateProcessEnv(process.env)
expect(spawn.calls.length).toBe(1)
expect(spawn.calls[0].command).toBe('/my/custom/bash')
expect(spawn.calls[0].args).toEqual(['-ilc', 'command awk \'BEGIN{for(v in ENVIRON) printf("%s=%s\\0",v,ENVIRON[v])}\''])
expect(spawn.calls[0].args).toEqual(['-ilc', 'command awk \'BEGIN{for(v in ENVIRON) printf("%s=%s%c", v, ENVIRON[v], 0)}\''])
expect(process.env).toEqual({
FOO: 'BAR=BAZ=QUUX',
'MULTILINE\nNAME': 'multiline\nvalue',

View File

@@ -14,8 +14,9 @@ const PLATFORMS_KNOWN_TO_WORK = new Set([
])
// Shell command that returns env var=value lines separated by \0s so that
// newlines are handled properly
const ENV_COMMAND = 'command awk \'BEGIN{for(v in ENVIRON) printf("%s=%s\\0",v,ENVIRON[v])}\''
// newlines are handled properly. Note: need to use %c to inject the \0s
// to work with some non GNU awks.
const ENV_COMMAND = 'command awk \'BEGIN{for(v in ENVIRON) printf("%s=%s%c", v, ENVIRON[v], 0)}\''
async function updateProcessEnv (launchEnv) {
let envToAssign