[ruby-core:95012] [Ruby master Bug#16173] ENV.delete returns nil when name does not exist and block given
From:
nobu@...
Date:
2019-09-21 07:09:29 UTC
List:
ruby-core #95012
Issue #16173 has been updated by nobu (Nobuyoshi Nakada).
Comparing with `Hash#delete`, it looks that the document is correct and the code is wrong.
```diff
diff --git i/hash.c w/hash.c
index 8b84a14484..7880178dc8 100644
--- i/hash.c
+++ w/hash.c
@@ -4779,7 +4779,7 @@ env_delete_m(VALUE obj, VALUE name)
VALUE val;
val = env_delete(name);
- if (NIL_P(val) && rb_block_given_p()) rb_yield(name);
+ if (NIL_P(val) && rb_block_given_p()) val = rb_yield(name);
return val;
}
diff --git i/test/ruby/test_env.rb w/test/ruby/test_env.rb
index b01c3b12ee..1a7656ea7d 100644
--- i/test/ruby/test_env.rb
+++ w/test/ruby/test_env.rb
@@ -107,6 +107,7 @@
assert_invalid_env {|v| ENV.delete(v)}
assert_nil(ENV.delete("TEST"))
assert_nothing_raised { ENV.delete(PATH_ENV) }
+ assert_equal("NO TEST", ENV.delete("TEST") {|name| "NO "+name})
end
def test_getenv
```
----------------------------------------
Bug #16173: ENV.delete returns nil when name does not exist and block given
https://bugs.ruby-lang.org/issues/16173#change-81639
* Author: burdettelamar@yahoo.com (Burdette Lamar)
* Status: Open
* Priority: Normal
* Assignee:
* Target version:
* ruby -v: ruby 2.6.4p104 (2019-08-28 revision 67798) [x64-mingw32]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Attached diff.txt:
* ENV.delete for nonexistent name and block given:
* Test enhanced to verify return value is nil.
* Documentation corrected to say that return value is nil, not value.
---Files--------------------------------
diff.txt (961 Bytes)
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>