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 {
|
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}. ` +
|
||||||
|
@ -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'
|
||||||
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user