fix(shared): trailing space in Windows elevation env vars (#1949)

This is a strange one. On Windows, putting a space before the
double-ampersand command concatenator makes the environment variable
value contain a trailing space. So for something like `set foo=bar &&
...` the variable `foo` will be `'bar '` instead of `'bar'`.

Change-Type: patch
Changelog-Entry: Fix trailing space in environment variables during Windows elevation.
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
This commit is contained in:
Juan Cruz Viotti 2018-01-04 07:47:10 -04:00 committed by Jonas Hermsmeier
parent 13758c9568
commit cb876436d4
2 changed files with 14 additions and 17 deletions

View File

@ -99,7 +99,12 @@ exports.getEnvironmentCommandPrefix = (environment) => {
} }
if (isWindows) { if (isWindows) {
return [ 'set', `${key}=${value}`, '&&' ] // Doing something like `set foo=bar &&` (notice
// the space before the first ampersand) would
// cause the environment variable's value to
// contain a trailing space.
// See https://superuser.com/a/57726
return [ 'set', `${key}=${value}&&` ]
} }
return [ `${key}=${value}` ] return [ `${key}=${value}` ]

View File

@ -45,8 +45,7 @@ describe('Shared: permissions', function () {
FOO: 'bar' FOO: 'bar'
})).to.deep.equal([ })).to.deep.equal([
'set', 'set',
'FOO=bar', 'FOO=bar&&',
'&&',
'call' 'call'
]) ])
}) })
@ -58,14 +57,11 @@ describe('Shared: permissions', function () {
BAZ: 'qux' BAZ: 'qux'
})).to.deep.equal([ })).to.deep.equal([
'set', 'set',
'FOO=bar', 'FOO=bar&&',
'&&',
'set', 'set',
'BAR=baz', 'BAR=baz&&',
'&&',
'set', 'set',
'BAZ=qux', 'BAZ=qux&&',
'&&',
'call' 'call'
]) ])
}) })
@ -77,8 +73,7 @@ describe('Shared: permissions', function () {
BAZ: undefined BAZ: undefined
})).to.deep.equal([ })).to.deep.equal([
'set', 'set',
'BAR=qux', 'BAR=qux&&',
'&&',
'call' 'call'
]) ])
}) })
@ -90,14 +85,11 @@ describe('Shared: permissions', function () {
BAZ: -1 BAZ: -1
})).to.deep.equal([ })).to.deep.equal([
'set', 'set',
'FOO=1', 'FOO=1&&',
'&&',
'set', 'set',
'BAR=0', 'BAR=0&&',
'&&',
'set', 'set',
'BAZ=-1', 'BAZ=-1&&',
'&&',
'call' 'call'
]) ])
}) })