diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-09-04 18:36:28 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-09-04 18:36:28 +0900 |
| commit | 6b302d80a364c9433af68a0d07a1a524c020e017 (patch) | |
| tree | b131099a62a243c3835b1100136b21f1a8e4d04f /src | |
| parent | 32aee72d295e2de3c890791b61ab9741b99912b1 (diff) | |
| download | mruby-6b302d80a364c9433af68a0d07a1a524c020e017.tar.gz mruby-6b302d80a364c9433af68a0d07a1a524c020e017.zip | |
instance variable name validation based on <ctype.h>; fix #2584
Diffstat (limited to 'src')
| -rw-r--r-- | src/variable.c | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/src/variable.c b/src/variable.c index 948bd1871..440a33948 100644 --- a/src/variable.c +++ b/src/variable.c @@ -542,23 +542,20 @@ mrb_iv_defined(mrb_state *mrb, mrb_value obj, mrb_sym sym) return mrb_obj_iv_defined(mrb, mrb_obj_ptr(obj), sym); } +#define identchar(c) (ISALNUM(c) || (c) == '_' || !ISASCII(c)) + MRB_API mrb_bool mrb_iv_p(mrb_state *mrb, mrb_sym iv_name) { const char *s; mrb_int i, len; - size_t j; - const char *invalid = "@$!? "; s = mrb_sym2name_len(mrb, iv_name, &len); if (len < 2) return FALSE; if (s[0] != '@') return FALSE; if (s[1] == '@') return FALSE; for (i=1; i<len; i++) { - char c = s[i]; - for (j=0; j<sizeof(invalid); j++) { - if (c == invalid[j]) return FALSE; - } + if (!identchar(s[i])) return FALSE; } return TRUE; } |
