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

Environment variables are case insensitive on Windows #6071

Open
p6rt opened this issue Feb 13, 2017 · 5 comments
Open

Environment variables are case insensitive on Windows #6071

p6rt opened this issue Feb 13, 2017 · 5 comments

Comments

@p6rt
Copy link

p6rt commented Feb 13, 2017

Migrated from rt.perl.org#130776 (status was 'open')

Searchable as RT130776$

@p6rt
Copy link
Author

p6rt commented Feb 13, 2017

From @nanis

$ echo %windir%
C​:\WINDOWS

$ echo %WINDIR%
C​:\WINDOWS

$ c​:\opt\perl6-mingw\bin\perl6 -e "say %*ENV<WINDIR>"
(Any)

$ c​:\opt\perl6-mingw\bin\perl6 -e "say %*ENV<windir>"
C​:\WINDOWS

$ c​:\opt\perl6-mingw\bin\perl6 -v
This is Rakudo version 2017.01 built on MoarVM version 2017.01
implementing Perl 6.c.

Both %*ENV<WINDIR> and %*ENV<windir> (as well as, e.g., %*ENV<WinDir>
etc) should return 'C​:\WINDOWS'.

-- Sinan

@p6rt
Copy link
Author

p6rt commented Feb 14, 2017

From @zoffixznet

On Mon, 13 Feb 2017 14​:38​:03 -0800, nanis@​cpan.org wrote​:

$ echo %windir%
C​:\WINDOWS

$ echo %WINDIR%
C​:\WINDOWS

$ c​:\opt\perl6-mingw\bin\perl6 -e "say %*ENV<WINDIR>"
(Any)

$ c​:\opt\perl6-mingw\bin\perl6 -e "say %*ENV<windir>"
C​:\WINDOWS

$ c​:\opt\perl6-mingw\bin\perl6 -v
This is Rakudo version 2017.01 built on MoarVM version 2017.01
implementing Perl 6.c.

Both %*ENV<WINDIR> and %*ENV<windir> (as well as, e.g., %*ENV<WinDir>
etc) should return 'C​:\WINDOWS'.

-- Sinan

What would be a good approach? Store them in whatever case they come in, but apply fc() when looking up keys?

If I dump all the vars with `set` I see all-uppercase, mixed-case, and all-lowercase vars. Perl 5 seems to uppercase them all (when I dump %ENV with Data​::Dumper). And that naturally leads to what to do with stuff like 'ß', which Perl 5 dumps out to me as `'▀' => '42',`


I'm thinking of just sticking a subclass of Hash to %*ENV on Windows, something along the lines of

  $ perl6 -e 'my %h := class :​: is Hash { method AT-KEY ($k) { nextwith $k.fc }; method ASSIGN-KEY ($k, $v) { nextwith $k.fc, $v } }.new; %h<Foo> = 42; dd %h; dd %h<foo>'

  {​:foo(42)}
  Int <element> = 42

@p6rt
Copy link
Author

p6rt commented Feb 14, 2017

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Feb 14, 2017

From @nanis

I am not sure what the right strategy is ... Perl 5 seems to work
mainly because they use the ANSI interfaces to get environment
variables ... which means you can't get the value of $ENV{iş}.

I opened this issue because I am going to think about it and thought
there should be something to reference.

The simple solution seems to work, but I do believe case needs to be preserved.

Anyway, this is a low priority issue and I am not even certain any
part of the Perl 6 machinery needs to be involved. Maybe it's
sufficient for client programs to case fold when looking for keys.

-- Sinan

@p6rt
Copy link
Author

p6rt commented Mar 2, 2017

From @nanis

I have done some research on this issue. The "correct" behavior seems
to be to match what Windows would do in cmd.exe. That would provide
the users with the least surprise.

Michael Kaplan's guidance[1] on file names seems to also describe how
Windows handles names of environment variables​:

For the uppercasing operation, you can use CharUpper, CharUpperBuff, or LCMapString
with the LCMAP_UPPERCASE flag (and *without* the LCMAP_LINGUISTIC_CASING flag!).
(emphasis in the original)

To test whether the same applied to names of environment variables as
well, I set the user locale to Turkish, and verified that iş was
mapped to IŞ and not İŞ on a computer where the OS code page was not
Turkish.

The most straightforward function to use is thus CharUpperBuffW[2].

[1]​: http://archives.miloush.net/michkap/archive/2005/10/17/481600.html
[2]​: https://msdn.microsoft.com/en-us/library/windows/desktop/ms647475(v=vs.85).aspx

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

No branches or pull requests

1 participant