-
Notifications
You must be signed in to change notification settings - Fork 12
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
fix: parse options.env
more similarly to process.env
#98
Conversation
which
lookups on Windows machines
Is this handling the case where |
@wraithgar |
We have always operated under the assumption that the windows environment variables were case insensitive. The docs at https://nodejs.org/api/process.html#process_process_env even say:
So, I think the answer to my first question then is "yes" this is handling the case where This will also need a test added for coverage purposes. |
If |
You are right. I was looking at |
Phew perfect, I think we understand the bug now. An affordance in that conditional to look for |
@wraithgar or maybe we can add a case-insensitive lookup function for finding env variables or would that be unnecessary? That would handle all sorts of weird |
Given as how we are trying to interpret It looks like node does special parsing of this parameter itself to account for this special quirk of environment variables let envKeys = [];
// Prototype values are intentionally included.
for (const key in env) {
ArrayPrototypePush(envKeys, key);
}
if (process.platform === 'win32') {
// On Windows env keys are case insensitive. Filter out duplicates,
// keeping only the first one (in lexicographic order)
const sawKey = new SafeSet();
envKeys = ArrayPrototypeFilter(
ArrayPrototypeSort(envKeys),
(key) => {
const uppercaseKey = StringPrototypeToUpperCase(key);
if (sawKey.has(uppercaseKey)) {
return false;
}
sawKey.add(uppercaseKey);
return true;
},
);
} This same logic may need to apply to both the |
@wraithgar what would be the best way to write a test case for this? Can we convert |
No that would just be testing how the code is written, not what it ultimately does. There is a test in In order to match node the keys in env should probably be sorted. |
@wraithgar should be ready |
which
lookups on Windows machinesoptions.env
more similarly to process.env
🤖 I have created a release *beep* *boop* --- ## [7.0.1](v7.0.0...v7.0.1) (2023-12-21) ### Bug Fixes * [`46fad5a`](46fad5a) [#98](#98) parse `options.env` more similarly to `process.env` (#98) (@thecodrr) ### Chores * [`d3ba687`](d3ba687) [#97](#97) postinstall for dependabot template-oss PR (@lukekarrys) * [`cf18492`](cf18492) [#97](#97) bump @npmcli/template-oss from 4.21.1 to 4.21.3 (@dependabot[bot]) * [`c72524e`](c72524e) [#95](#95) postinstall for dependabot template-oss PR (@lukekarrys) * [`8102197`](8102197) [#95](#95) bump @npmcli/template-oss from 4.19.0 to 4.21.1 (@dependabot[bot]) * [`3d54f38`](3d54f38) [#76](#76) postinstall for dependabot template-oss PR (@lukekarrys) * [`ca63a18`](ca63a18) [#76](#76) bump @npmcli/template-oss from 4.18.1 to 4.19.0 (@dependabot[bot]) * [`e3e359f`](e3e359f) [#74](#74) postinstall for dependabot template-oss PR (@lukekarrys) * [`cc8e9c9`](cc8e9c9) [#74](#74) bump @npmcli/template-oss from 4.18.0 to 4.18.1 (@dependabot[bot]) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This fix attempts to parse
options.env
in a similar way to how it is parsed inchild_process.spawn
, namely by doing a simple sorted case-insensitive lookup forpath
andpathext
.The intent is to support folks who pass in to opts
{ env: ...process.env}
, as this removes the built in case insensitivity that is present on the originalprocess.env
object.