1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[Bug #18905] Check symbol name types more strictly

This commit is contained in:
Nobuyoshi Nakada 2022-07-19 20:24:26 +09:00
parent 631b34ef95
commit 8f17591435
Notes: git 2022-07-20 00:24:10 +09:00
3 changed files with 18 additions and 6 deletions

View file

@ -378,7 +378,7 @@ rb_enc_symname_type(const char *name, long len, rb_encoding *enc, unsigned int a
if (m >= e || (*m != '_' && !ISALPHA(*m) && ISASCII(*m))) {
if (len > 1 && *(e-1) == '=') {
type = rb_enc_symname_type(name, len-1, enc, allowed_attrset);
if (type != ID_ATTRSET) return ID_ATTRSET;
if (allowed_attrset & (1U << type)) return ID_ATTRSET;
}
return -1;
}

View file

@ -93,16 +93,16 @@ module Test_Symbol
assert_symtype("@foo=", :attrset?)
assert_symtype("@@foo=", :attrset?)
assert_symtype("$foo=", :attrset?)
assert_symtype("0=", :attrset?)
assert_symtype("@=", :attrset?)
assert_symtype("@@=", :attrset?)
assert_not_symtype("0=", :attrset?)
assert_not_symtype("@=", :attrset?)
assert_not_symtype("@@=", :attrset?)
assert_not_symtype("foo", :attrset?)
assert_not_symtype("Foo", :attrset?)
assert_not_symtype("@foo", :attrset?)
assert_not_symtype("@@foo", :attrset?)
assert_not_symtype("$foo", :attrset?)
assert_not_symtype("[foo]", :attrset?)
assert_symtype("[foo]=", :attrset?)
assert_not_symtype("[foo]=", :attrset?)
assert_equal(:"foo=", Bug::Symbol.attrset("foo"))
assert_symtype(Bug::Symbol.attrset("foo"), :attrset?)
assert_equal(:"Foo=", Bug::Symbol.attrset("Foo"))
@ -114,7 +114,6 @@ module Test_Symbol
assert_equal(:"$foo=", Bug::Symbol.attrset("$foo"))
assert_symtype(Bug::Symbol.attrset("$foo"), :attrset?)
assert_equal(:"[foo]=", Bug::Symbol.attrset("[foo]"))
assert_symtype(Bug::Symbol.attrset("[foo]"), :attrset?)
assert_equal(:[]=, Bug::Symbol.attrset(:[]))
assert_symtype(Bug::Symbol.attrset("foo?="), :attrset?)
assert_equal(:"foo?=", Bug::Symbol.attrset(:foo?))

View file

@ -36,6 +36,19 @@ class TestSymbol < Test::Unit::TestCase
assert_eval_inspected(:"@@1", false)
assert_eval_inspected(:"@", false)
assert_eval_inspected(:"@@", false)
assert_eval_inspected(:"[]=")
assert_eval_inspected(:"[][]", false)
assert_eval_inspected(:"[][]=", false)
assert_eval_inspected(:"@=", false)
assert_eval_inspected(:"@@=", false)
assert_eval_inspected(:"@x=", false)
assert_eval_inspected(:"@@x=", false)
assert_eval_inspected(:"$$=", false)
assert_eval_inspected(:"$==", false)
assert_eval_inspected(:"$x=", false)
assert_eval_inspected(:"$$$=", false)
assert_eval_inspected(:"foo?=", false)
assert_eval_inspected(:"foo!=", false)
end
def assert_inspect_evaled(n)