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

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
This commit is contained in:
nobu 2013-04-24 05:04:01 +00:00
parent c262fda9eb
commit 531329a291
3 changed files with 19 additions and 13 deletions

View file

@ -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

15
parse.y
View file

@ -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);
}

View file

@ -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