Bug #7755

JSON::Generate#configure's argument conversion

Added by Marc-Andre Lafortune about 1 year ago. Updated about 1 year ago.

Assignee:Yui NARUSE
Target version:next minor
ruby -v:r38977 Backport:


I notice a tiny bug in ext/json/generator/generator.c:514

tmp = rb_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;

Bug is that rbconverttype never returns nil.

Either both rbconverttype are changed to rbcheckconvert_type, or these lines are simply replaced by:

opts = rb_convert_type(opts, T_HASH, "Hash", "to_hash");

I'd recommend this last option, for consistency with the rest of MRI.


#1 Updated by Marc-Andre Lafortune about 1 year ago

  • Subject changed from JSON::Generate#configure's argument conversion to JSON::Generate#configure's argument conversion

There's some more unreachable code in ext/json/parser/parser.rl:629

#2 Updated by Yui NARUSE about 1 year ago

  • Target version changed from 2.0.0 to next minor

Could you report it to upstream?

Also available in: Atom PDF