Skip to content
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(windows): fix env var glob casing #9429

Merged
merged 2 commits into from
Nov 14, 2024

Conversation

chris-olszewski
Copy link
Member

@chris-olszewski chris-olszewski commented Nov 12, 2024

Description

In #9424 a user had path as their Windows env var instead of Path or PATH. On Windows environment variables are case insensitive e.g. process.env.PATH and process.env.Path would both return the same. While fetching them might be the same std::env::vars returns the environment variable names cased as they were declared even though std::env::var is case insensitive on Windows.

Take for example the following code:

for (key, value) in std::env::vars() {
  println!("{key}: {value}");
  let lowercase = key.to_ascii_lowercase();
  println!("{lowercase}: {:?}", std::env::var(&lowercase));
}

On Windows it outputs:

...
PUBLIC: C:\Users\Public
public: Ok("C:\\Users\\Public")
SESSIONNAME: Console
sessionname: Ok("Console")
SystemDrive: C:
systemdrive: Ok("C:")
SystemRoot: C:\WINDOWS
systemroot: Ok("C:\\WINDOWS")
TEMP: C:\Users\Chris\AppData\Local\Temp
temp: Ok("C:\\Users\\Chris\\AppData\\Local\\Temp")
TMP: C:\Users\Chris\AppData\Local\Temp
tmp: Ok("C:\\Users\\Chris\\AppData\\Local\\Temp")

On macOs it outputs:

...
TMPDIR: /var/folders/3m/rxkycvgs5jgfvs0k9xcgp6km0000gn/T/
tmpdir: Err(NotPresent)
TMUX: /private/tmp/tmux-501/default,3104,0
tmux: Err(NotPresent)
TMUX_PANE: %4
tmux_pane: Err(NotPresent)
USER: olszewski
user: Err(NotPresent)
USER_ZDOTDIR: /Users/olszewski
user_zdotdir: Err(NotPresent)

Previously we had special casing for well known Windows env vars that were set differently between Command Prompt and Powershell, but would break if a user overwrote Path or PATH to path. This was brittle and a correct solution would require that we include all casing variations of all environment variables and users would also need to know how env vars were declared on their Windows system.

This fix is to make our env var wildcard handling case in

Testing Instructions

Added unit test to make sure we

Copy link

vercel bot commented Nov 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
examples-nonmonorepo ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 13, 2024 2:09pm
8 Skipped Deployments
Name Status Preview Comments Updated (UTC)
examples-basic-web ⬜️ Ignored (Inspect) Visit Preview Nov 13, 2024 2:09pm
examples-designsystem-docs ⬜️ Ignored (Inspect) Visit Preview Nov 13, 2024 2:09pm
examples-gatsby-web ⬜️ Ignored (Inspect) Nov 13, 2024 2:09pm
examples-kitchensink-blog ⬜️ Ignored (Inspect) Visit Preview Nov 13, 2024 2:09pm
examples-native-web ⬜️ Ignored (Inspect) Visit Preview Nov 13, 2024 2:09pm
examples-svelte-web ⬜️ Ignored (Inspect) Visit Preview Nov 13, 2024 2:09pm
examples-tailwind-web ⬜️ Ignored (Inspect) Visit Preview Nov 13, 2024 2:09pm
examples-vite-web ⬜️ Ignored (Inspect) Nov 13, 2024 2:09pm

@chris-olszewski
Copy link
Member Author

Holding on merging this until 2.3 is released

@chris-olszewski chris-olszewski merged commit e680dab into main Nov 14, 2024
40 checks passed
@chris-olszewski chris-olszewski deleted the olszewski/fix_windows_env_casing branch November 14, 2024 18:59
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.

2 participants