mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Fix class name validation in Struct.new
Before this patch:
$ bin/mruby -e 'p Struct.new("A-")'
#=> Struct::"A-"
After this patch:
$ bin/mruby -e 'p Struct.new("A-")'
#=> NameError: identifier A- needs to be constant
This commit is contained in:
@@ -212,7 +212,7 @@ make_struct(mrb_state *mrb, mrb_value name, mrb_value members, struct RClass *kl
|
||||
/* old style: should we warn? */
|
||||
mrb_to_str(mrb, name);
|
||||
id = mrb_obj_to_sym(mrb, name);
|
||||
if (!is_const_id(mrb, mrb_sym2name_len(mrb, id, NULL))) {
|
||||
if (!mrb_const_name_p(mrb, RSTRING_PTR(name), RSTRING_LEN(name))) {
|
||||
mrb_name_error(mrb, id, "identifier %S needs to be constant", name);
|
||||
}
|
||||
if (mrb_const_defined_at(mrb, mrb_obj_value(klass), id)) {
|
||||
|
||||
Reference in New Issue
Block a user