summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorFlorian Frank <flori@ping.de>2013-02-20 23:47:56 +0100
committerFlorian Frank <flori@ping.de>2013-02-21 00:16:55 +0100
commit22da7f38a2670a9afbd2352c7265697c5db8afb4 (patch)
treeea4926b64a904d1305332daf263ffdf4a68012a7 /ext
parentbe7320fe65ddb20998fa0d7bccfcddcbc7cb09b9 (diff)
downloadjson-22da7f38a2670a9afbd2352c7265697c5db8afb4.tar.gz
Try to convert first with to_hash, then to_h
rb_convert_type doesn't return if conversion fails, so use rb_check_convert_type and the raise vi rb_convert_type. Make sure, that this behaviour is consisten across all generator implementations. Fixes https://github.com/flori/json/issues/162
Diffstat (limited to 'ext')
-rw-r--r--ext/json/ext/generator/generator.c5
1 files changed, 1 insertions, 4 deletions
diff --git a/ext/json/ext/generator/generator.c b/ext/json/ext/generator/generator.c
index ae4593c..6180f15 100644
--- a/ext/json/ext/generator/generator.c
+++ b/ext/json/ext/generator/generator.c
@@ -511,11 +511,8 @@ static VALUE cState_configure(VALUE self, VALUE opts)
{
VALUE tmp;
GET_STATE(self);
- tmp = rb_convert_type(opts, T_HASH, "Hash", "to_hash");
+ tmp = rb_check_convert_type(opts, T_HASH, "Hash", "to_hash");
if (NIL_P(tmp)) tmp = rb_convert_type(opts, T_HASH, "Hash", "to_h");
- if (NIL_P(tmp)) {
- rb_raise(rb_eArgError, "opts has to be hash like or convertable into a hash");
- }
opts = tmp;
tmp = rb_hash_aref(opts, ID2SYM(i_indent));
if (RTEST(tmp)) {