diff options
| author | KOBAYASHI Shuji <[email protected]> | 2019-06-13 21:24:48 +0900 |
|---|---|---|
| committer | KOBAYASHI Shuji <[email protected]> | 2019-06-13 21:24:48 +0900 |
| commit | 9bd692bc67ee302bcbc359d0841458339c440fb4 (patch) | |
| tree | b3acb175c0b27b4af256949bdbb0b2031a00dd23 /src/class.c | |
| parent | 1a98b94100a6331753bae17e158d053b129ad1d3 (diff) | |
| download | mruby-9bd692bc67ee302bcbc359d0841458339c440fb4.tar.gz mruby-9bd692bc67ee302bcbc359d0841458339c440fb4.zip | |
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
Diffstat (limited to 'src/class.c')
| -rw-r--r-- | src/class.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/class.c b/src/class.c index 6ceaa0cfa..373f2aec7 100644 --- a/src/class.c +++ b/src/class.c @@ -77,6 +77,12 @@ mrb_class_name_class(mrb_state *mrb, struct RClass *outer, struct RClass *c, mrb mrb_obj_iv_set_force(mrb, (struct RObject*)c, nsym, name); } +mrb_bool +mrb_const_name_p(mrb_state *mrb, const char *name, mrb_int len) +{ + return len > 0 && ISUPPER(name[0]) && mrb_ident_p(name+1, len-1); +} + static void setup_class(mrb_state *mrb, struct RClass *outer, struct RClass *c, mrb_sym id) { @@ -1852,18 +1858,12 @@ mrb_mod_undef(mrb_state *mrb, mrb_value mod) return mrb_nil_value(); } -static mrb_bool -const_name_p(mrb_state *mrb, const char *name, mrb_int len) -{ - return len > 0 && ISUPPER(name[0]) && mrb_ident_p(name+1, len-1); -} - static void check_const_name_sym(mrb_state *mrb, mrb_sym id) { mrb_int len; const char *name = mrb_sym2name_len(mrb, id, &len); - if (!const_name_p(mrb, name, len)) { + if (!mrb_const_name_p(mrb, name, len)) { mrb_name_error(mrb, id, "wrong constant name %S", mrb_sym2str(mrb, id)); } } |
