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

parse.y: invalid instance/class variable names

* parse.y (parse_atmark): mere atmark and two atmarks without
  succeeding identifiers are invalid as instance/class variable
  names.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48220 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-11-01 06:45:17 +00:00
parent 3dce236bf5
commit b5ba1dcdf0
3 changed files with 14 additions and 2 deletions

View file

@ -1,3 +1,9 @@
Sat Nov 1 15:45:15 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (parse_atmark): mere atmark and two atmarks without
succeeding identifiers are invalid as instance/class variable
names.
Sat Nov 1 06:31:41 2014 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* ext/win32ole/win32ole_variant.c: use typed data.

View file

@ -7575,9 +7575,13 @@ parse_atmark(struct parser_params *parser, const enum lex_state_e last_state)
tokadd('@');
c = nextc();
}
if (c != -1 && (ISDIGIT(c) || !parser_is_identchar())) {
if (c == -1 || ISSPACE(c)) {
compile_error(PARSER_ARG "unexpected @");
return 0;
}
else if (ISDIGIT(c) || !parser_is_identchar()) {
pushback(c);
if (tokidx == 1) {
if (result == tIVAR) {
compile_error(PARSER_ARG "`@%c' is not allowed as an instance variable name", c);
}
else {

View file

@ -650,10 +650,12 @@ x = __ENCODING__
def test_invalid_instance_variable
assert_raise(SyntaxError) { eval('@#') }
assert_raise(SyntaxError) { eval('@') }
end
def test_invalid_class_variable
assert_raise(SyntaxError) { eval('@@1') }
assert_raise(SyntaxError) { eval('@@') }
end
def test_invalid_char