aboutsummaryrefslogtreecommitdiffstats
path: root/sprintf.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-11-11 00:03:15 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-11-11 00:03:15 +0000
commitc5487f08b75ce31ce8673a56d6a12c5e0076befb (patch)
tree4ca44c50485fddc5c357d97b3858e6c0c3f2bb7b /sprintf.c
parent8f90345421247b7c863a06c09db7f550cf838045 (diff)
downloadruby-c5487f08b75ce31ce8673a56d6a12c5e0076befb.tar.gz
sprintf.c: hash default value
* sprintf.c (rb_str_format): respect default value of a hash. no longer raises KeyError unless the default value of the hash is nil. [ruby-core:71354] [Bug #11661] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52530 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sprintf.c')
-rw-r--r--sprintf.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/sprintf.c b/sprintf.c
index 705d3cece5..5c0f94005c 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -605,11 +605,11 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
}
CHECKNAMEARG(start, len, enc);
get_hash(&hash, argc, argv);
- sym = rb_check_symbol_cstr(start + 1,
- len - 2 /* without parenthesis */,
- enc);
- if (sym != Qnil) nextvalue = rb_hash_lookup2(hash, sym, Qundef);
- if (nextvalue == Qundef) {
+ sym = rb_cstr_intern(start + 1,
+ len - 2 /* without parenthesis */,
+ enc);
+ nextvalue = rb_hash_aref(hash, sym);
+ if (NIL_P(nextvalue) && !FL_TEST(hash, HASH_PROC_DEFAULT)) {
rb_enc_raise(enc, rb_eKeyError, "key%.*s not found", len, start);
}
if (term == '}') goto format_s;