diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-04-24 05:04:01 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-04-24 05:04:01 +0000 |
commit | 531329a29166b75a303da3ac2072278ad081dd08 (patch) | |
tree | 97a1d7335ae66e8fea8483c684327f26a38201e1 | |
parent | c262fda9eb8fd750989f2588378b366378398f7b (diff) | |
download | ruby-531329a29166b75a303da3ac2072278ad081dd08.tar.gz |
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.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40436 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | parse.y | 15 | ||||
-rw-r--r-- | test/ruby/test_symbol.rb | 9 |
3 files changed, 19 insertions, 13 deletions
@@ -1,3 +1,11 @@ +Wed Apr 24 14:03:59 2013 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * 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@zacharyscott.net> * string.c: Document String#setbyte return value by @gjmurakami-10gen @@ -5129,7 +5129,7 @@ ripper_dispatch_delayed_token(struct parser_params *parser, int t) #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 *parser) 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 *parser) } 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, const char *e, rb_encoding *enc) ++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); } diff --git a/test/ruby/test_symbol.rb b/test/ruby/test_symbol.rb index 89b7b4f8c9..02cc804933 100644 --- a/test/ruby/test_symbol.rb +++ b/test/ruby/test_symbol.rb @@ -64,11 +64,10 @@ class TestSymbol < Test::Unit::TestCase 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 |