Actions
Bug #11677
closed52530の変更により、sprintfの引数のhashにkeyが存在していてもvalueがnilのときにKeyErrorがでるようになってしまった。
Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.3.0dev (trunk 52534) [x86_64-darwin14]
Description
def test_named_with_nil
h = { key: nil, key2: "key2_val" }
assert_equal("key is , key2 is key2_val", "key is %{key}, key2 is %{key2}" % h)
end
のようなテストが2.2.3では通るのですが、trunkでは
KeyError: key{key} not found
となります。
"a.hoge is %{a}, b.fuga is %{b}" % { a: a.hoge, b: b.fuga }
のように書きたいときにvalueがnilでないことのチェックする必要がでるため、
今まで通りkeyが存在するときは例外が発生しないように修正したいです。
Files
Updated by yui-knk (Kaneko Yuichiro) almost 9 years ago
- File deleted (
0001-Not-raise-KeyError-when-an-arg-hash-of-sprintf-has-k.patch)
Updated by nobu (Nobuyoshi Nakada) almost 9 years ago
- Status changed from Open to Closed
Applied in changeset r52537.
sprintf.c: nil value is valid
- sprintf.c (rb_str_format): look up the key, then get default
value and raise KeyError if the returned value is nil.
[ruby-dev:49338] [Ruby trunk - Bug #11677]
Updated by yui-knk (Kaneko Yuichiro) almost 9 years ago
ありがとうございます。
Updated by naruse (Yui NARUSE) almost 9 years ago
- Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN to 2.0.0: DONTNEED, 2.1: DONTNEED, 2.2: DONTNEED
Updated by usa (Usaku NAKAMURA) almost 9 years ago
- Related to Bug #11661: sprintf causes a KeyError instead of using a default value for hash substitution added
Actions
Like0
Like0Like0Like0Like0Like0Like0