From fe5493cad633ab9eef6d535db3ac20cb26facfc7 Mon Sep 17 00:00:00 2001 From: Paula Camargo Date: Mon, 6 Jun 2022 17:14:05 -0400 Subject: [PATCH 1/4] Fix regex expression --- src/client/common/variables/environment.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/common/variables/environment.ts b/src/client/common/variables/environment.ts index bce6d2ca17e9..dcf3581414ca 100644 --- a/src/client/common/variables/environment.ts +++ b/src/client/common/variables/environment.ts @@ -114,7 +114,7 @@ function parseEnvLine(line: string): [string, string] { // https://github.com/motdotla/dotenv/blob/master/lib/main.js#L32 // We don't use dotenv here because it loses ordering, which is // significant for substitution. - const match = line.match(/^\s*([a-zA-Z]\w*)\s*=\s*(.*?)?\s*$/); + const match = line.match(/^\s*(_?)([a-zA-Z]\w*)\s*=\s*(.*?)?\s*$/); if (!match) { return ['', '']; } From 276b9dbb1b7e72bad4c269f700d8ed3de973f63c Mon Sep 17 00:00:00 2001 From: Paula Camargo Date: Tue, 7 Jun 2022 11:56:12 -0400 Subject: [PATCH 2/4] Fix tests --- src/client/common/variables/environment.ts | 4 ++-- src/test/common/variables/envVarsService.unit.test.ts | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/client/common/variables/environment.ts b/src/client/common/variables/environment.ts index dcf3581414ca..c483e1df388e 100644 --- a/src/client/common/variables/environment.ts +++ b/src/client/common/variables/environment.ts @@ -114,13 +114,13 @@ function parseEnvLine(line: string): [string, string] { // https://github.com/motdotla/dotenv/blob/master/lib/main.js#L32 // We don't use dotenv here because it loses ordering, which is // significant for substitution. - const match = line.match(/^\s*(_?)([a-zA-Z]\w*)\s*=\s*(.*?)?\s*$/); + const match = line.match(/^\s*((_?)[a-zA-Z]\w*)\s*=\s*(.*?)?\s*$/); if (!match) { return ['', '']; } const name = match[1]; - let value = match[2]; + let value = match[3]; if (value && value !== '') { if (value[0] === "'" && value[value.length - 1] === "'") { value = value.substring(1, value.length - 1); diff --git a/src/test/common/variables/envVarsService.unit.test.ts b/src/test/common/variables/envVarsService.unit.test.ts index aeedfdb94c00..5647f990065f 100644 --- a/src/test/common/variables/envVarsService.unit.test.ts +++ b/src/test/common/variables/envVarsService.unit.test.ts @@ -395,7 +395,7 @@ Path=/usr/x:/usr/y SPAM=1234 ham=5678 Eggs=9012 -_bogus1=... +_bogus1=1234 1bogus2=... bogus 3=... bogus.4=... @@ -406,12 +406,13 @@ VAR_2=7890 `); expect(vars).to.not.equal(undefined, 'Variables is undefiend'); - expect(Object.keys(vars!)).lengthOf(5, 'Incorrect number of variables'); + expect(Object.keys(vars!)).lengthOf(6, 'Incorrect number of variables'); expect(vars).to.have.property('SPAM', '1234', 'value is invalid'); expect(vars).to.have.property('ham', '5678', 'value is invalid'); expect(vars).to.have.property('Eggs', '9012', 'value is invalid'); expect(vars).to.have.property('VAR1', '3456', 'value is invalid'); expect(vars).to.have.property('VAR_2', '7890', 'value is invalid'); + expect(vars).to.have.property('_bogus1', '1234', 'value is invalid'); }); test('Empty values become empty string', () => { From 9cd7b0aa21e158c25c4f0228eb24ed1c2c81d4bf Mon Sep 17 00:00:00 2001 From: Paula Camargo Date: Tue, 7 Jun 2022 13:35:16 -0400 Subject: [PATCH 3/4] Fix reg exp --- src/client/common/variables/environment.ts | 4 ++-- src/test/common/variables/envVarsService.unit.test.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/client/common/variables/environment.ts b/src/client/common/variables/environment.ts index c483e1df388e..2672eb535ca3 100644 --- a/src/client/common/variables/environment.ts +++ b/src/client/common/variables/environment.ts @@ -114,13 +114,13 @@ function parseEnvLine(line: string): [string, string] { // https://github.com/motdotla/dotenv/blob/master/lib/main.js#L32 // We don't use dotenv here because it loses ordering, which is // significant for substitution. - const match = line.match(/^\s*((_?)[a-zA-Z]\w*)\s*=\s*(.*?)?\s*$/); + const match = line.match(/^\s*(_*[a-zA-Z]\w*)\s*=\s*(.*?)?\s*$/); if (!match) { return ['', '']; } const name = match[1]; - let value = match[3]; + let value = match[2]; if (value && value !== '') { if (value[0] === "'" && value[value.length - 1] === "'") { value = value.substring(1, value.length - 1); diff --git a/src/test/common/variables/envVarsService.unit.test.ts b/src/test/common/variables/envVarsService.unit.test.ts index 5647f990065f..ac5400cbf371 100644 --- a/src/test/common/variables/envVarsService.unit.test.ts +++ b/src/test/common/variables/envVarsService.unit.test.ts @@ -395,7 +395,6 @@ Path=/usr/x:/usr/y SPAM=1234 ham=5678 Eggs=9012 -_bogus1=1234 1bogus2=... bogus 3=... bogus.4=... @@ -403,6 +402,7 @@ bogus-5=... bogus~6=... VAR1=3456 VAR_2=7890 +_VAR_3=3456 `); expect(vars).to.not.equal(undefined, 'Variables is undefiend'); @@ -412,7 +412,7 @@ VAR_2=7890 expect(vars).to.have.property('Eggs', '9012', 'value is invalid'); expect(vars).to.have.property('VAR1', '3456', 'value is invalid'); expect(vars).to.have.property('VAR_2', '7890', 'value is invalid'); - expect(vars).to.have.property('_bogus1', '1234', 'value is invalid'); + expect(vars).to.have.property('_VAR_3', '3456', 'value is invalid'); }); test('Empty values become empty string', () => { From 706e4f393b74ac41daa8b36d2128cdcba0986fdf Mon Sep 17 00:00:00 2001 From: Paula Camargo Date: Tue, 7 Jun 2022 13:42:25 -0400 Subject: [PATCH 4/4] Fix test --- src/test/common/variables/envVarsService.unit.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/common/variables/envVarsService.unit.test.ts b/src/test/common/variables/envVarsService.unit.test.ts index ac5400cbf371..590803ea135e 100644 --- a/src/test/common/variables/envVarsService.unit.test.ts +++ b/src/test/common/variables/envVarsService.unit.test.ts @@ -402,7 +402,7 @@ bogus-5=... bogus~6=... VAR1=3456 VAR_2=7890 -_VAR_3=3456 +_VAR_3=1234 `); expect(vars).to.not.equal(undefined, 'Variables is undefiend'); @@ -412,7 +412,7 @@ _VAR_3=3456 expect(vars).to.have.property('Eggs', '9012', 'value is invalid'); expect(vars).to.have.property('VAR1', '3456', 'value is invalid'); expect(vars).to.have.property('VAR_2', '7890', 'value is invalid'); - expect(vars).to.have.property('_VAR_3', '3456', 'value is invalid'); + expect(vars).to.have.property('_VAR_3', '1234', 'value is invalid'); }); test('Empty values become empty string', () => {