Project

General

Profile

Bug #11677 » 0001-Not-raise-KeyError-when-an-arg-hash-of-sprintf-has-k.patch

yui-knk (Kaneko Yuichiro), 11/11/2015 09:28 AM

View differences:

sprintf.c
609 609
				     len - 2 /* without parenthesis */,
610 610
				     enc);
611 611
		nextvalue = rb_hash_aref(hash, sym);
612
		if (NIL_P(nextvalue) && !FL_TEST(hash, HASH_PROC_DEFAULT)) {
612
                if (NIL_P(nextvalue) && (rb_hash_has_key(hash, sym) == Qfalse) && !FL_TEST(hash, HASH_PROC_DEFAULT)) {
613 613
		    rb_enc_raise(enc, rb_eKeyError, "key%.*s not found", len, start);
614 614
		}
615 615
		if (term == '}') goto format_s;
test/ruby/test_sprintf.rb
415 415
    assert_equal("hello world", "hello %{location}" % h)
416 416
    assert_equal("hello world", "hello %<location>s" % h)
417 417
  end
418

  
419
  def test_named_with_nil
420
    h = { key: nil, key2: "key2_val" }
421
    assert_equal("key is , key2 is key2_val", "key is %{key}, key2 is %{key2}" % h)
422
  end
418 423
end
419
-