Ignore leading and trailing whitespace when parsing env vars

Change-type: patch
Closes: #644
Signed-off-by: Cameron Diver <cameron@resin.io>
This commit is contained in:
Cameron Diver 2018-05-21 10:32:04 +01:00
parent 82123d3591
commit bea0b00804
No known key found for this signature in database
GPG Key ID: 69264F9C923F55C1
2 changed files with 12 additions and 1 deletions

View File

@ -4,7 +4,7 @@ import { EnvVarObject } from './types';
export function envArrayToObject(env: string[]): EnvVarObject {
const toPair = (keyVal: string) => {
const m = keyVal.match(/^([^=]+)=(.*)$/);
const m = keyVal.match(/^([^=]+)=\s*(.*)\s*$/);
if (m == null) {
console.log(`WARNING: Could not correctly parse env var ${keyVal}. ` +
'Please fix this var and recreate the container.');

View File

@ -36,3 +36,14 @@ describe 'conversions', ->
expect(conversion.envArrayToObject('')).to.deep.equal({})
expect(conversion.envArrayToObject([])).to.deep.equal({})
expect(conversion.envArrayToObject(1)).to.deep.equal({})
it 'should ignore leading and trailing whitespace', ->
expect(conversion.envArrayToObject([
'TEST=\ntest'
'TEST2=test\n'
'TEST3=\ntest\n'
])).to.deep.equal({
TEST: 'test'
TEST2: 'test'
TEST3: 'test'
})