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:
parent
c262fda9eb
commit
531329a291
3 changed files with 19 additions and 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>
|
Wed Apr 24 13:54:00 2013 Zachary Scott <zachary@zacharyscott.net>
|
||||||
|
|
||||||
* string.c: Document String#setbyte return value by @gjmurakami-10gen
|
* string.c: Document String#setbyte return value by @gjmurakami-10gen
|
||||||
|
|
15
parse.y
15
parse.y
|
@ -5129,7 +5129,7 @@ ripper_dispatch_delayed_token(struct parser_params *parser, int t)
|
||||||
#define parser_encoding_name() (current_enc->name)
|
#define parser_encoding_name() (current_enc->name)
|
||||||
#define parser_mbclen() mbclen((lex_p-1),lex_pend,current_enc)
|
#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 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_is_identchar() (!parser->eofp && is_identchar((lex_p-1),lex_pend,current_enc))
|
||||||
|
|
||||||
#define parser_isascii() ISASCII(*(lex_p-1))
|
#define parser_isascii() ISASCII(*(lex_p-1))
|
||||||
|
@ -7829,9 +7829,7 @@ parser_yylex(struct parser_params *parser)
|
||||||
case '\"': /* $": already loaded files */
|
case '\"': /* $": already loaded files */
|
||||||
tokadd('$');
|
tokadd('$');
|
||||||
tokadd(c);
|
tokadd(c);
|
||||||
tokfix();
|
goto gvar;
|
||||||
set_yylval_name(rb_intern(tok()));
|
|
||||||
return tGVAR;
|
|
||||||
|
|
||||||
case '-':
|
case '-':
|
||||||
tokadd('$');
|
tokadd('$');
|
||||||
|
@ -7842,10 +7840,11 @@ parser_yylex(struct parser_params *parser)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
pushback(c);
|
pushback(c);
|
||||||
|
pushback('-');
|
||||||
|
return '$';
|
||||||
}
|
}
|
||||||
gvar:
|
gvar:
|
||||||
tokfix();
|
set_yylval_name(rb_intern3(tok(), tokidx, current_enc));
|
||||||
set_yylval_name(rb_intern(tok()));
|
|
||||||
return tGVAR;
|
return tGVAR;
|
||||||
|
|
||||||
case '&': /* $&: last match */
|
case '&': /* $&: last match */
|
||||||
|
@ -10010,8 +10009,8 @@ is_special_global_name(const char *m, const char *e, rb_encoding *enc)
|
||||||
++m;
|
++m;
|
||||||
break;
|
break;
|
||||||
case '-':
|
case '-':
|
||||||
++m;
|
if (++m >= e) return 0;
|
||||||
if (m < e && is_identchar(m, e, enc)) {
|
if (is_identchar(m, e, enc)) {
|
||||||
if (!ISASCII(*m)) mb = 1;
|
if (!ISASCII(*m)) mb = 1;
|
||||||
m += rb_enc_mbclen(m, e, enc);
|
m += rb_enc_mbclen(m, e, enc);
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,11 +64,10 @@ class TestSymbol < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_inspect_dollar
|
def test_inspect_dollar
|
||||||
# 4) :$- always treats next character literally:
|
# 4) :$- always treats next character literally:
|
||||||
sym = "$-".intern
|
assert_raise(SyntaxError) {eval ':$-'}
|
||||||
assert_nothing_raised(SyntaxError) {assert_equal(sym, eval(':$-'))}
|
assert_raise(SyntaxError) {eval ":$-\n"}
|
||||||
assert_nothing_raised(SyntaxError) {assert_equal(sym, eval(":$-\n"))}
|
assert_raise(SyntaxError) {eval ":$- "}
|
||||||
assert_nothing_raised(SyntaxError) {assert_equal(sym, eval(":$- "))}
|
assert_raise(SyntaxError) {eval ":$-#"}
|
||||||
assert_nothing_raised(SyntaxError) {assert_equal(sym, eval(":$-#"))}
|
|
||||||
assert_raise(SyntaxError) {eval ':$-('}
|
assert_raise(SyntaxError) {eval ':$-('}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue