mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-02-20 17:52:51 +00:00
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:
parent
82123d3591
commit
bea0b00804
@ -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.');
|
||||
|
@ -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'
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user