mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Compare environment variable names in those manor [Bug #16798]
This commit is contained in:
parent
e042380e0e
commit
08529a6115
Notes:
git
2020-04-18 23:09:30 +09:00
2 changed files with 21 additions and 3 deletions
22
hash.c
22
hash.c
|
@ -6343,13 +6343,29 @@ env_invert(VALUE _)
|
||||||
return rb_hash_invert(env_to_hash());
|
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
|
static int
|
||||||
env_replace_i(VALUE key, VALUE val, VALUE keys)
|
env_replace_i(VALUE key, VALUE val, VALUE keys)
|
||||||
{
|
{
|
||||||
|
env_name(key);
|
||||||
env_aset(key, val);
|
env_aset(key, val);
|
||||||
if (rb_ary_includes(keys, key)) {
|
|
||||||
rb_ary_delete(keys, key);
|
keylist_delete(keys, key);
|
||||||
}
|
|
||||||
return ST_CONTINUE;
|
return ST_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -433,6 +433,8 @@ class TestEnv < Test::Unit::TestCase
|
||||||
ENV["foo"] = "xxx"
|
ENV["foo"] = "xxx"
|
||||||
ENV.replace({"foo"=>"bar", "baz"=>"qux"})
|
ENV.replace({"foo"=>"bar", "baz"=>"qux"})
|
||||||
check(ENV.to_hash.to_a, [%w(foo bar), %w(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
|
end
|
||||||
|
|
||||||
def test_update
|
def test_update
|
||||||
|
|
Loading…
Reference in a new issue