diff options
author | Felipe Gasper <felipe@felipegasper.com> | 2021-04-09 23:08:39 -0400 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2021-04-16 17:11:31 -0600 |
commit | 50352f1687ab2f02685a380668c889111cdeeee9 (patch) | |
tree | 394c42dc6affad5d3729a7f58b694f3e2d67f243 /t | |
parent | 3e22b590c6d72471558aaf41940c266859f988b8 (diff) | |
download | perl-50352f1687ab2f02685a380668c889111cdeeee9.tar.gz |
Set %ENV keys using the same byte-string logic as setting %ENV values.
Issue #18636: This extends the work from
613c63b465f01af4e535fdc6c1c17e7470be5aad to %ENV keys. Previously
if you assigned an upgraded string as a key in %ENV, the string’s
internal PV representation was sent to the OS. Now the string is
“soft downgraded” before being given to the OS; if the downgrade
fails--i.e., if the string contains code points above 255--then
a warning is printed, and the string’s utf8 is assigned to the
environment, as happens with %ENV values.
A new internal macro, MgSV, is created to facilitate this work.
Diffstat (limited to 't')
-rw-r--r-- | t/op/magic.t | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/t/op/magic.t b/t/op/magic.t index 46d1beafb1..c2180afb9d 100644 --- a/t/op/magic.t +++ b/t/op/magic.t @@ -5,7 +5,7 @@ BEGIN { chdir 't' if -d 't'; require './test.pl'; set_up_inc( '../lib' ); - plan (tests => 192); # some tests are run in BEGIN block + plan (tests => 196); # some tests are run in BEGIN block } # Test that defined() returns true for magic variables created on the fly, @@ -764,6 +764,11 @@ SKIP: { $forced = $ENV{foo} = $chars; ok(!utf8::is_utf8($forced) && $forced eq $bytes, 'ENV store downgrades utf8 in SV'); env_is(foo => $bytes, 'ENV store downgrades utf8 in setenv'); + fail 'chars should still be wide!' if !utf8::is_utf8($chars); + $ENV{$chars} = 'widekey'; + env_is("eh zero \x{A0}" => 'widekey', 'ENV store downgrades utf8 key in setenv'); + fail 'chars should still be wide!' if !utf8::is_utf8($chars); + is( delete($ENV{$chars}), 'widekey', 'delete(%ENV) downgrades utf8 key' ); # warn when downgrading utf8 is not possible $chars = "X-Day \x{1998}"; @@ -773,6 +778,12 @@ SKIP: { local $SIG{__WARN__} = sub { ++$warned if $_[0] =~ /^Wide character in setenv/; print "# @_" }; $forced = $ENV{foo} = $chars; ok($warned == 1, 'ENV store warns about wide characters'); + + fail 'chars should still be wide!' if !utf8::is_utf8($chars); + $ENV{$chars} = 'widekey'; + env_is($forced => 'widekey', 'ENV store takes utf8-encoded key in setenv'); + + ok($warned == 2, 'ENV key store warns about wide characters'); } ok(!utf8::is_utf8($forced) && $forced eq $bytes, 'ENV store encodes high utf8 in SV'); env_is(foo => $bytes, 'ENV store encodes high utf8 in SV'); |