summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--parse.y10
-rw-r--r--test/ripper/test_parser_events.rb22
-rw-r--r--test/ripper/test_scanner_events.rb6
4 files changed, 31 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 7235b943f73..163dba3a7fe 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed May 8 13:07:17 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * parse.y (parser_yylex): fail if $, @, @@ are not followed by a valid
+ name character. [ruby-core:54846] [Bug #8375].
+
Wed May 8 13:06:31 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* include/ruby/ruby.h (ISGRAPH): add missing macro.
diff --git a/parse.y b/parse.y
index b6778558219..a83f85f1f45 100644
--- a/parse.y
+++ b/parse.y
@@ -7876,7 +7876,8 @@ parser_yylex(struct parser_params *parser)
default:
if (!parser_is_identchar()) {
pushback(c);
- return '$';
+ compile_error(PARSER_ARG "`$%c' is not allowed as a global variable name", c);
+ return 0;
}
case '0':
tokadd('$');
@@ -7891,7 +7892,8 @@ parser_yylex(struct parser_params *parser)
tokadd('@');
c = nextc();
}
- if (c != -1 && ISDIGIT(c)) {
+ if (c != -1 && (ISDIGIT(c) || !parser_is_identchar())) {
+ pushback(c);
if (tokidx == 1) {
compile_error(PARSER_ARG "`@%c' is not allowed as an instance variable name", c);
}
@@ -7900,10 +7902,6 @@ parser_yylex(struct parser_params *parser)
}
return 0;
}
- if (!parser_is_identchar()) {
- pushback(c);
- return '@';
- }
break;
case '_':
diff --git a/test/ripper/test_parser_events.rb b/test/ripper/test_parser_events.rb
index 44180617adf..c9b56902457 100644
--- a/test/ripper/test_parser_events.rb
+++ b/test/ripper/test_parser_events.rb
@@ -24,6 +24,10 @@ class TestRipper::ParserEvents < Test::Unit::TestCase
dp.parse.to_s
end
+ def compile_error(str)
+ parse(str, :compile_error) {|e, msg| return msg}
+ end
+
def test_program
thru_program = false
assert_equal '[void()]', parse('', :on_program) {thru_program = true}
@@ -1167,8 +1171,20 @@ class TestRipper::ParserEvents < Test::Unit::TestCase
end
def test_unterminated_regexp
- compile_error = false
- parse('/', :compile_error) {|e, msg| compile_error = msg}
- assert_equal("unterminated regexp meets end of file", compile_error)
+ assert_equal("unterminated regexp meets end of file", compile_error('/'))
+ end
+
+ def test_invalid_instance_variable_name
+ assert_equal("`@1' is not allowed as an instance variable name", compile_error('@1'))
+ assert_equal("`@%' is not allowed as an instance variable name", compile_error('@%'))
+ end
+
+ def test_invalid_class_variable_name
+ assert_equal("`@@1' is not allowed as a class variable name", compile_error('@@1'))
+ assert_equal("`@@%' is not allowed as a class variable name", compile_error('@@%'))
+ end
+
+ def test_invalid_global_variable_name
+ assert_equal("`$%' is not allowed as a global variable name", compile_error('$%'))
end
end if ripper_test
diff --git a/test/ripper/test_scanner_events.rb b/test/ripper/test_scanner_events.rb
index 66ae07cc6b3..a96edef0633 100644
--- a/test/ripper/test_scanner_events.rb
+++ b/test/ripper/test_scanner_events.rb
@@ -92,7 +92,7 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase
def test_location
assert_location ""
assert_location " "
- assert_location "@"
+ assert_location ":"
assert_location "\n"
assert_location "\r\n"
assert_location "\n\n\n\n\n\r\n\n\n"
@@ -842,8 +842,8 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase
def test_CHAR
assert_equal [],
scan('CHAR', "")
- assert_equal ["@"],
- scan('CHAR', "@")
+ assert_equal ["?a"],
+ scan('CHAR', "?a")
assert_equal [],
scan('CHAR', "@ivar")
end