Skip to content

Commit 1e1d904

Browse files
committed
Allow colons in default values for environment variables
Anything after a third colon is silently ignored in variable substitution, which prevents using default values with colons in them (e.g. URLs or image:tag). This limits the split at 3 parts by joining any additional parts back together. A similar fix was previously proposed in #882 a couple years ago. Open to exploring different solutions (e.g. quoting the entire default value or escaping colons) if there is still a desire to retain the ability to introduce more than 2 arguments in variable substitution. Fixes #719, #883.
1 parent f4ee5d0 commit 1e1d904

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

src/spec-common/variableSubstitution.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ function evaluateSingleVariable(replace: Replace, match: string, variable: strin
8585
const parts = variable.split(':');
8686
if (parts.length > 1) {
8787
variable = parts[0];
88-
args = parts.slice(1);
88+
// Preserve colons in the default value (e.g. `${localEnv:VAR:image:tag}`).
89+
args = parts.length > 2 ? [parts[1], parts.slice(2).join(':')] : [parts[1]];
8990
}
9091

9192
return replace(match, variable, args);

src/test/variableSubstitution.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ describe('Variable substitution', function () {
131131
env: {
132132
},
133133
}, raw);
134-
assert.strictEqual(result.foo, 'bardefaultbar');
134+
assert.strictEqual(result.foo, 'bardefault:a:b:cbar');
135135
});
136136

137137
it(`container environment variables with default value if they do not exist`, async () => {

0 commit comments

Comments
 (0)