[前][次][番号順一覧][スレッド一覧]

ruby-changes:36139

From: nobu <ko1@a...>
Date: Sat, 1 Nov 2014 15:45:28 +0900 (JST)
Subject: [ruby-changes:36139] nobu:r48220 (trunk): parse.y: invalid instance/class variable names

nobu	2014-11-01 15:45:17 +0900 (Sat, 01 Nov 2014)

  New Revision: 48220

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48220

  Log:
    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.

  Modified files:
    trunk/ChangeLog
    trunk/parse.y
    trunk/test/ruby/test_parse.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 48219)
+++ ChangeLog	(revision 48220)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Nov  1 15:45:15 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@n...>
 
 	* ext/win32ole/win32ole_variant.c: use typed data.
Index: parse.y
===================================================================
--- parse.y	(revision 48219)
+++ parse.y	(revision 48220)
@@ -7575,9 +7575,13 @@ parse_atmark(struct parser_params *parse https://github.com/ruby/ruby/blob/trunk/parse.y#L7575
 	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 {
Index: test/ruby/test_parse.rb
===================================================================
--- test/ruby/test_parse.rb	(revision 48219)
+++ test/ruby/test_parse.rb	(revision 48220)
@@ -650,10 +650,12 @@ x = __ENCODING__ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_parse.rb#L650
 
   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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]