ruby-changes:60820
From: Nobuyoshi <ko1@a...>
Date: Sat, 18 Apr 2020 23:09:30 +0900 (JST)
Subject: [ruby-changes:60820] 08529a6115 (master): Compare environment variable names in those manor [Bug #16798]
https://git.ruby-lang.org/ruby.git/commit/?id=08529a6115 From 08529a61153e5c40f57a65272211357511d6e6db Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Sat, 18 Apr 2020 20:39:07 +0900 Subject: Compare environment variable names in those manor [Bug #16798] diff --git a/hash.c b/hash.c index 769af0d..71bbfea 100644 --- a/hash.c +++ b/hash.c @@ -6343,13 +6343,29 @@ env_invert(VALUE _) https://github.com/ruby/ruby/blob/trunk/hash.c#L6343 return rb_hash_invert(env_to_hash()); } +static void +keylist_delete(VALUE keys, VALUE key) +{ + long keylen, elen; + const char *keyptr, *eptr; + RSTRING_GETMEM(key, keyptr, keylen); + for (long i=0; i<RARRAY_LEN(keys); i++) { + VALUE e = RARRAY_AREF(keys, i); + RSTRING_GETMEM(e, eptr, elen); + if (elen != keylen) continue; + if (!ENVNMATCH(keyptr, eptr, elen)) continue; + rb_ary_delete_at(keys, i); + return; + } +} + static int env_replace_i(VALUE key, VALUE val, VALUE keys) { + env_name(key); env_aset(key, val); - if (rb_ary_includes(keys, key)) { - rb_ary_delete(keys, key); - } + + keylist_delete(keys, key); return ST_CONTINUE; } diff --git a/test/ruby/test_env.rb b/test/ruby/test_env.rb index f93cd50..02cd3b8 100644 --- a/test/ruby/test_env.rb +++ b/test/ruby/test_env.rb @@ -433,6 +433,8 @@ class TestEnv < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_env.rb#L433 ENV["foo"] = "xxx" ENV.replace({"foo"=>"bar", "baz"=>"qux"}) check(ENV.to_hash.to_a, [%w(foo bar), %w(baz qux)]) + ENV.replace({"Foo"=>"Bar", "Baz"=>"Qux"}) + check(ENV.to_hash.to_a, [%w(Foo Bar), %w(Baz Qux)]) end def test_update -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/