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

ruby-changes:28384

From: nobu <ko1@a...>
Date: Wed, 24 Apr 2013 14:04:12 +0900 (JST)
Subject: [ruby-changes:28384] nobu:r40436 (trunk): parse.y: disallow $-

nobu	2013-04-24 14:04:01 +0900 (Wed, 24 Apr 2013)

  New Revision: 40436

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

  Log:
    parse.y: disallow $-
    
    * parse.y (parser_yylex): disallow $- without following identifier
      character.  [ruby-talk:406969]
    * parse.y (is_special_global_name): mere $- is not a valid global
      variable name.

  Modified files:
    trunk/ChangeLog
    trunk/parse.y
    trunk/test/ruby/test_symbol.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 40435)
+++ ChangeLog	(revision 40436)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Apr 24 14:03:59 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* parse.y (parser_yylex): disallow $- without following identifier
+	  character.  [ruby-talk:406969]
+
+	* parse.y (is_special_global_name): mere $- is not a valid global
+	  variable name.
+
 Wed Apr 24 13:54:00 2013  Zachary Scott  <zachary@z...>
 
 	* string.c: Document String#setbyte return value by @gjmurakami-10gen
Index: parse.y
===================================================================
--- parse.y	(revision 40435)
+++ parse.y	(revision 40436)
@@ -5129,7 +5129,7 @@ ripper_dispatch_delayed_token(struct par https://github.com/ruby/ruby/blob/trunk/parse.y#L5129
 #define parser_encoding_name()  (current_enc->name)
 #define parser_mbclen()  mbclen((lex_p-1),lex_pend,current_enc)
 #define parser_precise_mbclen()  rb_enc_precise_mbclen((lex_p-1),lex_pend,current_enc)
-#define is_identchar(p,e,enc) (rb_enc_isalnum(*(p),(enc)) || (*(p)) == '_' || !ISASCII(*(p)))
+#define is_identchar(p,e,enc) (rb_enc_isalnum((unsigned char)(*(p)),(enc)) || (*(p)) == '_' || !ISASCII(*(p)))
 #define parser_is_identchar() (!parser->eofp && is_identchar((lex_p-1),lex_pend,current_enc))
 
 #define parser_isascii() ISASCII(*(lex_p-1))
@@ -7829,9 +7829,7 @@ parser_yylex(struct parser_params *parse https://github.com/ruby/ruby/blob/trunk/parse.y#L7829
 	  case '\"':		/* $": already loaded files */
 	    tokadd('$');
 	    tokadd(c);
-	    tokfix();
-	    set_yylval_name(rb_intern(tok()));
-	    return tGVAR;
+	    goto gvar;
 
 	  case '-':
 	    tokadd('$');
@@ -7842,10 +7840,11 @@ parser_yylex(struct parser_params *parse https://github.com/ruby/ruby/blob/trunk/parse.y#L7840
 	    }
 	    else {
 		pushback(c);
+		pushback('-');
+		return '$';
 	    }
 	  gvar:
-	    tokfix();
-	    set_yylval_name(rb_intern(tok()));
+	    set_yylval_name(rb_intern3(tok(), tokidx, current_enc));
 	    return tGVAR;
 
 	  case '&':		/* $&: last match */
@@ -10010,8 +10009,8 @@ is_special_global_name(const char *m, co https://github.com/ruby/ruby/blob/trunk/parse.y#L10009
 	++m;
 	break;
       case '-':
-	++m;
-	if (m < e && is_identchar(m, e, enc)) {
+	if (++m >= e) return 0;
+	if (is_identchar(m, e, enc)) {
 	    if (!ISASCII(*m)) mb = 1;
 	    m += rb_enc_mbclen(m, e, enc);
 	}
Index: test/ruby/test_symbol.rb
===================================================================
--- test/ruby/test_symbol.rb	(revision 40435)
+++ test/ruby/test_symbol.rb	(revision 40436)
@@ -64,11 +64,10 @@ class TestSymbol < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_symbol.rb#L64
 
   def test_inspect_dollar
     # 4) :$- always treats next character literally:
-    sym = "$-".intern
-    assert_nothing_raised(SyntaxError) {assert_equal(sym, eval(':$-'))}
-    assert_nothing_raised(SyntaxError) {assert_equal(sym, eval(":$-\n"))}
-    assert_nothing_raised(SyntaxError) {assert_equal(sym, eval(":$- "))}
-    assert_nothing_raised(SyntaxError) {assert_equal(sym, eval(":$-#"))}
+    assert_raise(SyntaxError) {eval ':$-'}
+    assert_raise(SyntaxError) {eval ":$-\n"}
+    assert_raise(SyntaxError) {eval ":$- "}
+    assert_raise(SyntaxError) {eval ":$-#"}
     assert_raise(SyntaxError) {eval ':$-('}
   end
 

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

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