mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-01-22 20:38:21 +00:00
Merge pull request #901 from balena-io/fix-whitespace-handling
Fix whitespace handling in environment variables
This commit is contained in:
commit
b03338ca8e
@ -4,7 +4,7 @@ import { EnvVarObject } from './types';
|
||||
|
||||
export function envArrayToObject(env: string[]): EnvVarObject {
|
||||
const toPair = (keyVal: string) => {
|
||||
const m = keyVal.match(/^([^=]+)=\s*(.*)\s*$/);
|
||||
const m = keyVal.match(/^([^=]+)=([^]*)$/);
|
||||
if (m == null) {
|
||||
console.log(
|
||||
`WARNING: Could not correctly parse env var ${keyVal}. ` +
|
||||
|
@ -37,13 +37,17 @@ describe 'conversions', ->
|
||||
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'
|
||||
})
|
||||
it 'should correctly handle whitespace', ->
|
||||
expect(conversion.envArrayToObject([
|
||||
'key1= test',
|
||||
'key2=test\ntest',
|
||||
'key3=test ',
|
||||
'key4= test '
|
||||
'key5=test\r\ntest',
|
||||
])).to.deep.equal({
|
||||
key1: ' test',
|
||||
key2: 'test\ntest',
|
||||
key3: 'test ',
|
||||
key4: ' test ',
|
||||
key5: 'test\r\ntest'
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user