Project

General

Profile

Actions

Bug #11677

closed

52530の変更により、sprintfの引数のhashにkeyが存在していてもvalueがnilのときにKeyErrorがでるようになってしまった。

Added by yui-knk (Kaneko Yuichiro) over 8 years ago. Updated over 8 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.3.0dev (trunk 52534) [x86_64-darwin14]
[ruby-dev:49338]

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


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #11661: sprintf causes a KeyError instead of using a default value for hash substitutionClosedmatz (Yukihiro Matsumoto)Actions
Actions #1

Updated by yui-knk (Kaneko Yuichiro) over 8 years ago

  • File deleted (0001-Not-raise-KeyError-when-an-arg-hash-of-sprintf-has-k.patch)
Actions #3

Updated by nobu (Nobuyoshi Nakada) over 8 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) over 8 years ago

ありがとうございます。

Updated by naruse (Yui NARUSE) over 8 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
Actions #6

Updated by usa (Usaku NAKAMURA) over 8 years ago

  • Related to Bug #11661: sprintf causes a KeyError instead of using a default value for hash substitution added
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0