Merge pull request #901 from balena-io/fix-whitespace-handling

Fix whitespace handling in environment variables
This commit is contained in:
CameronDiver 2019-02-12 12:27:14 +00:00 committed by GitHub
commit b03338ca8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 11 deletions

View File

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

View File

@ -37,13 +37,17 @@ describe 'conversions', ->
expect(conversion.envArrayToObject([])).to.deep.equal({}) expect(conversion.envArrayToObject([])).to.deep.equal({})
expect(conversion.envArrayToObject(1)).to.deep.equal({}) expect(conversion.envArrayToObject(1)).to.deep.equal({})
it 'should ignore leading and trailing whitespace', -> it 'should correctly handle whitespace', ->
expect(conversion.envArrayToObject([ expect(conversion.envArrayToObject([
'TEST=\ntest' 'key1= test',
'TEST2=test\n' 'key2=test\ntest',
'TEST3=\ntest\n' 'key3=test ',
])).to.deep.equal({ 'key4= test '
TEST: 'test' 'key5=test\r\ntest',
TEST2: 'test' ])).to.deep.equal({
TEST3: 'test' key1: ' test',
}) key2: 'test\ntest',
key3: 'test ',
key4: ' test ',
key5: 'test\r\ntest'
})