diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-04-18 20:39:07 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2020-04-18 23:09:01 +0900 |
commit | 08529a61153e5c40f57a65272211357511d6e6db (patch) | |
tree | 48849ace0916fe02bf9d6c291d31047a34c54540 /hash.c | |
parent | e042380e0e2d32c30e5c1ddb9ce0df81e15d44a0 (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.c | 22 |
1 files changed, 19 insertions, 3 deletions
@@ -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; } |