Skip to content

fix: substitute every ${VAR} reference when merging env files - #1829

Open
Alexandre Kohler (kwy404) wants to merge 1 commit into
microsoft:mainfrom
kwy404:fix/env-file-repeated-var-substitution
Open

Alexandre Kohler (kwy404) wants to merge 1 commit into
microsoft:mainfrom
kwy404:fix/env-file-repeated-var-substitution

Conversation

@kwy404

Copy link
Copy Markdown

Problem

mergeEnvVariables expands ${VAR} references in env file values (the python.envFile file, the project .env and API overrides) with String.prototype.replace and a string pattern. That has two effects:

  • Only the first reference to a variable is replaced. With ROOT=/home/user in the base environment, PATHS=${ROOT}/a:${ROOT}/b becomes /home/user/a:${ROOT}/b.
  • $ sequences in the substituted value are read as replacement patterns. A base value of pa$$word comes out as pa$word.

Fix

Use split(token).join(value), which replaces every occurrence and inserts the value as is. (replaceAll is not available with the ES2020 lib target.)

Tests

Added src/test/features/execution/envVarUtils.unit.test.ts, which merges a value with a repeated ${ROOT} reference and a ${SECRET} whose base value contains $$. It fails before the fix (actual /home/user/a:${ROOT}/b) and passes after it.

  • npm run unittest (Windows, Node 24): 2430 passing, 4 pending.
  • eslint and prettier pass on the changed files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant