From 22da7f38a2670a9afbd2352c7265697c5db8afb4 Mon Sep 17 00:00:00 2001 From: Florian Frank Date: Wed, 20 Feb 2013 23:47:56 +0100 Subject: 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 --- ext/json/ext/generator/generator.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'ext') 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)) { -- cgit v1.2.1