Project

General

Profile

Actions

Bug #7755

closed

JSON::Generate#configure's argument conversion

Added by marcandre (Marc-Andre Lafortune) over 9 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Normal
Target version:
ruby -v:
r38977
[ruby-core:51740]

Description

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 rb_convert_type never returns nil.

Either both rb_convert_type are changed to rb_check_convert_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.

Actions

Also available in: Atom PDF