From dc40609e1ef012899f6bb6419d872781b42f12bd Mon Sep 17 00:00:00 2001 From: Christian Grotheer Date: Thu, 29 Aug 2024 11:48:40 +0200 Subject: [PATCH 1/3] add test for variable substitution with default value containing a colon --- src/test/variableSubstitution.test.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/test/variableSubstitution.test.ts b/src/test/variableSubstitution.test.ts index e95002464..9c2a973d2 100644 --- a/src/test/variableSubstitution.test.ts +++ b/src/test/variableSubstitution.test.ts @@ -88,6 +88,21 @@ describe('Variable substitution', function () { assert.strictEqual(result.foo, 'bardefaultbar'); }); + it(`environment variables with default value containing colon if they do not exist`, async () => { + const raw = { + foo: 'bar${localEnv:baz:de:fault}bar' + }; + const result = substitute({ + platform: 'linux', + localWorkspaceFolder: '/foo/bar', + containerWorkspaceFolder: '/baz/blue', + configFile: URI.file('/foo/bar/baz.json'), + env: { + }, + }, raw); + assert.strictEqual(result.foo, 'barde:faultbar'); + }); + it(`environment variables without default value if they do not exist`, async () => { const raw = { foo: 'bar${localEnv:baz}bar' From 843f913dbf176f787c325f9b119e18a75479ca86 Mon Sep 17 00:00:00 2001 From: Christian Grotheer Date: Thu, 29 Aug 2024 12:06:01 +0200 Subject: [PATCH 2/3] separate variable arguments correctly --- src/spec-common/variableSubstitution.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spec-common/variableSubstitution.ts b/src/spec-common/variableSubstitution.ts index d973f0cd6..d430c7a76 100644 --- a/src/spec-common/variableSubstitution.ts +++ b/src/spec-common/variableSubstitution.ts @@ -82,7 +82,7 @@ function evaluateSingleVariable(replace: Replace, match: string, variable: strin // try to separate variable arguments from variable name let args: string[] = []; - const parts = variable.split(':'); + const parts = variable.split(':', 3); if (parts.length > 1) { variable = parts[0]; args = parts.slice(1); From 1002a413b5ca976912d6a5a8c56dd5e6cb86f60b Mon Sep 17 00:00:00 2001 From: Christian Grotheer Date: Wed, 11 Sep 2024 09:26:11 +0200 Subject: [PATCH 3/3] Update variableSubstitution.ts fix limitting parts of variable substitution --- src/spec-common/variableSubstitution.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/spec-common/variableSubstitution.ts b/src/spec-common/variableSubstitution.ts index d430c7a76..77f8658aa 100644 --- a/src/spec-common/variableSubstitution.ts +++ b/src/spec-common/variableSubstitution.ts @@ -82,10 +82,15 @@ function evaluateSingleVariable(replace: Replace, match: string, variable: strin // try to separate variable arguments from variable name let args: string[] = []; + const parts = variable.split(':'); + const limitedParts = [ + ...parts.slice(0, 2), + parts.slice(2).join(':') + ]; const parts = variable.split(':', 3); - if (parts.length > 1) { - variable = parts[0]; - args = parts.slice(1); + if (limitedParts.length > 1) { + variable = limitedParts[0]; + args = limitedParts.slice(1); } return replace(match, variable, args); @@ -168,4 +173,4 @@ function devcontainerIdForLabels(idLabels: Record): string { .toString(32) .padStart(52, '0'); return uniqueId; -} \ No newline at end of file +}