summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authornagachika <nagachika@ruby-lang.org>2020-07-25 12:00:39 +0900
committernagachika <nagachika@ruby-lang.org>2020-07-25 12:00:39 +0900
commit89f06ce8b8a887f12b53ea190d79a58e98b59008 (patch)
tree983a679a9ac164a09e252dab313460e918dfd047 /hash.c
parent2e9626fddd168bd12352b4f5dc3412c6a33ce44e (diff)
merge revision(s) 08529a61153e5c40f57a65272211357511d6e6db: [Backport #16798]
Compare environment variable names in those manor [Bug #16798]
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/hash.c b/hash.c
index b546f6246b..dd78d2d8e1 100644
--- a/hash.c
+++ b/hash.c
@@ -6106,13 +6106,29 @@ env_invert(VALUE _)
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;
}