-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
canonicalize Windows environment variables to uppercase #30593
Conversation
Aside: I noticed the design here has a resource leak here for |
CI failures seem unrelated. |
Hooray, green CI! |
I think this qualifies as a minor change — almost any code that this could break was buggy anyway. For example, the following code would now break on Windows: ENV["foo"]="bar"
env = copy(ENV)
env["foo"] # now fails because the key is called "FOO" but this code was buggy — it would fail anyway if there were already an environment variable In practice, I looked over the existing packages that call |
@vtjnash, can we leave fixing the potential resource leak (for when you don't finish the iterator) for another PR, since that is an unrelated issue? Or do you want me to fix it here? |
Later PR |
@StefanKarpinski, do you have any opinion on this? It's a slightly tricky case for compatibility vs correctness. |
I think it seems like a good idea and you have gone to admirable lengths to make it correct (i.e. using Windows own case tables), not just almost correct (using our own case tables). Seems good for a minor release to me. Should have a NEWS entry and maybe a mention in the |
Added NEWS and documentation as suggested, thanks. |
CI failures are an unrelated Travis glitch (and everything was green before the latest commit, which just updated documentation). I think this should be good to merge. |
Tried to kick them (travis failed to start the jobs), although still gtg whenever you want to merge from my perspective. |
Since this is what we're recommending, wouldn't it make sense to just convert |
I'm not sure what you mean? It already says that portable code should not rely on lower case being preserved. |
I guess my issue is about what the meaning of that sentence fragment is. Does it mean that the programmer should be aware that |
Stefan, relying on lower case being preserved also was and is a problem if you make a copy of ENV, as described above: #30593 (comment) |
How about rephrasing it as:
|
That does clarify it. |
This PR mostly fixes #29334 by canonicalizing Windows environment variables (which are case-insensitive case-preserving) to uppercase when they are iterated, copied, etcetera.
Otherwise it is easy to write buggy code for Windows by following our
setenv
documentation, e.g.For example, I found code "in the wild" that does problematic things like this in Conda.jl, BinDeps.jl, Documenter.jl, the REPL, and
Base.runtests
— all of these examples don't take into account the case-insensitivity of Windows environment variables, and all should be fixed by this PR.It still doesn't throw if the user explicitly writes something like
merge!(ENV, Dict("key" => "1", "KEY" => "2"))
, but that could be addressed in a separate PR … that seems like a much less pressing problem to me.