[前][次][番号順一覧][スレッド一覧]

ruby-changes:65761

From: usa <ko1@a...>
Date: Mon, 5 Apr 2021 07:48:37 +0900 (JST)
Subject: [ruby-changes:65761] fe85a3d527 (ruby_2_6): merge revision(s) 08529a61153e5c40f57a65272211357511d6e6db: [Backport #16798]

https://git.ruby-lang.org/ruby.git/commit/?id=fe85a3d527

From fe85a3d5271c4e3aeda42ec32e9c3f9ee02b6897 Mon Sep 17 00:00:00 2001
From: usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
Date: Sun, 4 Apr 2021 22:48:27 +0000
Subject: merge revision(s) 08529a61153e5c40f57a65272211357511d6e6db: [Backport
 #16798]

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


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@67917 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
---
 hash.c                | 22 +++++++++++++++++++---
 test/ruby/test_env.rb |  2 ++
 version.h             |  2 +-
 3 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/hash.c b/hash.c
index e8be71b..38440f4 100644
--- a/hash.c
+++ b/hash.c
@@ -5652,13 +5652,29 @@ env_invert(void) https://github.com/ruby/ruby/blob/trunk/hash.c#L5652
     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(Qnil, 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 6343642..e9fb252 100644
--- a/test/ruby/test_env.rb
+++ b/test/ruby/test_env.rb
@@ -440,6 +440,8 @@ class TestEnv < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_env.rb#L440
     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
diff --git a/version.h b/version.h
index 395ec2a..e2d334f 100644
--- a/version.h
+++ b/version.h
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L1
 #define RUBY_VERSION "2.6.7"
 #define RUBY_RELEASE_DATE "2021-04-05"
-#define RUBY_PATCHLEVEL 176
+#define RUBY_PATCHLEVEL 177
 
 #define RUBY_RELEASE_YEAR 2021
 #define RUBY_RELEASE_MONTH 4
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]