summaryrefslogtreecommitdiff
path: root/hash.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2020-04-18 20:39:07 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-04-18 23:09:01 +0900
commit08529a61153e5c40f57a65272211357511d6e6db (patch)
tree48849ace0916fe02bf9d6c291d31047a34c54540 /hash.c
parente042380e0e2d32c30e5c1ddb9ce0df81e15d44a0 (diff)
Compare environment variable names in those manor [Bug #16798]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3040
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 769af0df7d..71bbfea4a0 100644
--- a/hash.c
+++ b/hash.c
@@ -6343,13 +6343,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;
}