Commit 4e36aa5
Support escaping template variables in environment values (#6935)
## What's the problem this PR addresses?
<!-- Describe the rationale of your PR. -->
<!-- Link all issues that it closes. (Closes/Resolves #xxxx.) -->
Resolves #6491
```sh
$ yarn init -2
$ echo 'CYPRESS_DOWNLOAD_PATH_TEMPLATE="\${endpoint}/\${platform}-\${arch}/cypress.zip"' > .env.yarn
$ yarn node -p 'process.env.CYPRESS_DOWNLOAD_PATH_TEMPLATE'
# AS-IS
Usage Error: Environment variable not found (endpoint)
# TO-BE
${endpoint}/${platform}-${arch}/cypress.zip
```
## How did you fix it?
<!-- A detailed description of your implementation. -->
Support escaping template variables in environment variable values. When
a template variable is escaped with a backslash (e.g., `\${VAR}`), it is
now preserved as a literal string `${VAR}` instead of being replaced
with an actual environment variable value.
I updated the regex to match values starting with a backslash. When a
match starts with a backslash, it is treated as an escaped template and
returns the value with only the backslash removed (`match.slice(1)`).
## Checklist
<!--- Don't worry if you miss something, chores are automatically
tested. -->
<!--- This checklist exists to help you remember doing the chores when
you submit a PR. -->
<!--- Put an `x` in all the boxes that apply. -->
- [x] I have read the [Contributing
Guide](https://yarnpkg.com/advanced/contributing).
<!-- See
https://yarnpkg.com/advanced/contributing#preparing-your-pr-to-be-released
for more details. -->
<!-- Check with `yarn version check` and fix with `yarn version check
-i` -->
- [x] I have set the packages that need to be released for my changes to
be effective.
<!-- The "Testing chores" workflow validates that your PR follows our
guidelines. -->
<!-- If it doesn't pass, click on it to see details as to what your PR
might be missing. -->
- [x] I will check that all automated PR checks pass before the PR gets
reviewed.
---------
Co-authored-by: Maël Nison <nison.mael@gmail.com>1 parent b9ccd93 commit 4e36aa5
File tree
3 files changed
+88
-5
lines changed- .yarn/versions
- packages/yarnpkg-core
- sources
- tests
3 files changed
+88
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
471 | 471 | | |
472 | 472 | | |
473 | 473 | | |
474 | | - | |
| 474 | + | |
475 | 475 | | |
476 | | - | |
477 | | - | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
478 | 479 | | |
| 480 | + | |
479 | 481 | | |
480 | 482 | | |
481 | 483 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
6 | 45 | | |
7 | 46 | | |
8 | 47 | | |
| |||
135 | 174 | | |
136 | 175 | | |
137 | 176 | | |
138 | | - | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
139 | 180 | | |
140 | 181 | | |
141 | 182 | | |
| |||
150 | 191 | | |
151 | 192 | | |
152 | 193 | | |
153 | | - | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
154 | 199 | | |
155 | 200 | | |
156 | 201 | | |
0 commit comments