Project

General

Profile

Actions

Bug #16798

closed

ENV.replace on Windows with a variable name not respecting case will clear it

Added by deivid (David Rodríguez) about 4 years ago. Updated almost 3 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:97941]

Description

On Windows, environment variable names are case insensitive:

PS C:\Users\deivi> ruby -e "puts ENV['Path']; ENV['PATH'] = 'foo'; puts ENV['Path']"                                                                                                                                                     C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Ruby26-x64\bin;C:\Ruby25-x64\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Ruby27-x64\bin;C:\Ruby25-x64\bin
foo

PS C:\Users\deivi> ruby -e "puts ENV['Path']; ENV.update('PATH' => 'foo'); puts ENV['Path']"                                                                                                                                             C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Ruby26-x64\bin;C:\Ruby25-x64\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Ruby27-x64\bin;C:\Ruby25-x64\bin
foo

However, with ENV.replace, if you don't use the "canonical casing" (as given by ENV.keys, for example), the environment variable will be cleared.

PS C:\Users\deivi> ruby -e "puts ENV['Path']; ENV.replace('PATH' => 'foo'); puts ENV['Path']"                                                                                                                                                 C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Ruby26-x64\bin;C:\Ruby25-x64\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Ruby27-x64\bin;C:\Ruby25-x64\bin


This is unexpected to me.

Actions #1

Updated by nobu (Nobuyoshi Nakada) about 4 years ago

  • Status changed from Open to Closed

Applied in changeset git|08529a61153e5c40f57a65272211357511d6e6db.


Compare environment variable names in those manor [Bug #16798]

Actions #2

Updated by nobu (Nobuyoshi Nakada) about 4 years ago

  • Backport changed from 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN to 2.5: REQUIRED, 2.6: REQUIRED, 2.7: REQUIRED

Updated by deivid (David Rodríguez) about 4 years ago

Thanks for the quick fix @nobu (Nobuyoshi Nakada), and for setting the backports! <3

Updated by nagachika (Tomoyuki Chikanaga) over 3 years ago

  • Backport changed from 2.5: REQUIRED, 2.6: REQUIRED, 2.7: REQUIRED to 2.5: REQUIRED, 2.6: REQUIRED, 2.7: DONE

ruby_2_7 89f06ce8b8a887f12b53ea190d79a58e98b59008 merged revision(s) 08529a61153e5c40f57a65272211357511d6e6db.

Updated by usa (Usaku NAKAMURA) about 3 years ago

  • Backport changed from 2.5: REQUIRED, 2.6: REQUIRED, 2.7: DONE to 2.5: REQUIRED, 2.6: DONE, 2.7: DONE

backported into ruby_2_6 at r67917

Updated by vo.x (Vit Ondruch) almost 3 years ago

The backport breaks on RHEL7:

hash.c: In function 'keylist_delete':
hash.c:5661:5: error: 'for' loop initial declarations are only allowed in C99 mode
     for (long i=0; i<RARRAY_LEN(keys); i++) {
     ^
hash.c:5661:5: note: use option -std=c99 or -std=gnu99 to compile your code

Interestingly, I have not met this issue in Ruby 2.7. Are there implicitly the -std=c99 or -std=gnu99 options?

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0