Commit 4ab81cf
authored
fix: substitute every ${VAR} reference when merging env files (#1829)
## 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.1 parent 14cecd8 commit 4ab81cf
2 files changed
Lines changed: 14 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
0 commit comments