Skip to content

Allow variable substitution default value containing a colon #882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update variableSubstitution.ts
fix limitting parts of variable substitution
  • Loading branch information
grthr authored Sep 11, 2024
commit 1002a413b5ca976912d6a5a8c56dd5e6cb86f60b
13 changes: 9 additions & 4 deletions src/spec-common/variableSubstitution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would prevent us from introducing additional arguments in the future because we would break existing configs.

Also: split() with the limit argument does not include the remaining part of the text after the limit was hit. This would need a closer look.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we would need additional arguments in the future after the current ones it would be nice to be able to escape the : in the default value. Would this be an approach to go for?

something like "WEBSITE_URL": "${localEnv:WEBSITE_URL:https\://example.com"

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);
Expand Down Expand Up @@ -168,4 +173,4 @@ function devcontainerIdForLabels(idLabels: Record<string, string>): string {
.toString(32)
.padStart(52, '0');
return uniqueId;
}
}