Project

General

Profile

Bug #11677

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

Added by yui-knk (Kaneko Yuichiro) almost 4 years ago. Updated almost 4 years ago.

Status:
Closed
Priority:
Normal
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

Related to Ruby master - Bug #11661: sprintf causes a KeyError instead of using a default value for hash substitutionClosedActions

Associated revisions

Revision 56e3b493
Added by nobu (Nobuyoshi Nakada) almost 4 years ago

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]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52537 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 52537
Added by nobu (Nobuyoshi Nakada) almost 4 years ago

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]

Revision 52537
Added by nobu (Nobuyoshi Nakada) almost 4 years ago

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]

Revision 52537
Added by nobu (Nobuyoshi Nakada) almost 4 years ago

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]

Revision 52537
Added by nobu (Nobuyoshi Nakada) almost 4 years ago

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]

Revision 52537
Added by nobu (Nobuyoshi Nakada) almost 4 years ago

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]

History

#1

Updated by yui-knk (Kaneko Yuichiro) almost 4 years ago

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

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

ありがとうございます。

Updated by naruse (Yui NARUSE) almost 4 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
#6

Updated by usa (Usaku NAKAMURA) almost 4 years ago

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

Also available in: Atom PDF