Skip to content

Fix variable interpolation in .env files loaded through envFile - #14828

Open
Abdelhadi Salmaoui (abdelhadi703) wants to merge 1 commit into
microsoft:mainfrom
abdelhadi703:fix/envfile-interpolation
Open

Abdelhadi Salmaoui (abdelhadi703) wants to merge 1 commit into
microsoft:mainfrom
abdelhadi703:fix/envfile-interpolation

Conversation

@abdelhadi703

Copy link
Copy Markdown

.env files are supposed to support variable interpolation, but when such a file is
loaded through envFile, the values keep their ${...} references and the variable is
never substituted.

With a file like

USER=admin
EMAIL=${USER}@example.org

EMAIL came out as the literal ${USER}@example.org. Later, when the debug
configuration gets expanded, ${USER} is looked up as a launch.json variable, isn't
found, and prints "Invalid variable reference ${USER} in string". The env var that was
meant to land in the debuggee doesn't.

I made ParsedEnvironmentFile resolve ${VAR} while it parses each line, against the
variables already read from the file plus the process environment. That's the behaviour
the dotenv format describes. A reference to a name we don't know is left untouched, so
${workspaceFolder} and the other launch.json variables keep working exactly as before.

Three tests were added to the existing ParsedEnvironmentFile suite: a reference to a
variable defined earlier in the same file, a reference coming from the initial
environment, and an unknown reference staying literal.

Testing: ran the ParsedEnvironmentFile suite with the repo's pinned @types/node and
mocha (installed from the public registry, since the Extension .npmrc points at the
private feed). 10 passing with this change. On current main the two interpolation tests
fail with ${USER}@example.org where admin@example.org is expected, and the 7 existing
tests pass either way.

Fixes #13781.

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

Labels

None yet

Projects

Status: Pull Request

Development

Successfully merging this pull request may close these issues.

[bug] launch.json envFile not capable of variable interpolation

1 participant