зеркало из https://github.com/github/ruby.git
[Bug #19882] Reject tokens invalid as symbols
This commit is contained in:
Родитель
5a7f5bb0de
Коммит
89802078f9
|
@ -535,8 +535,8 @@ assert_syntax_error "unterminated string meets end of file", '().."', '[ruby-dev
|
|||
assert_equal %q{[]}, %q{$&;[]}, '[ruby-dev:31068]'
|
||||
assert_syntax_error "syntax error, unexpected *, expecting '}'", %q{{*0}}, '[ruby-dev:31072]'
|
||||
assert_syntax_error "`@0' is not allowed as an instance variable name", %q{@0..0}, '[ruby-dev:31095]'
|
||||
assert_syntax_error "identifier $00 is not valid to get", %q{$00..0}, '[ruby-dev:31100]'
|
||||
assert_syntax_error "identifier $00 is not valid to set", %q{0..$00=1}
|
||||
assert_syntax_error "`$00' is not allowed as a global variable name", %q{$00..0}, '[ruby-dev:31100]'
|
||||
assert_syntax_error "`$00' is not allowed as a global variable name", %q{0..$00=1}
|
||||
assert_equal %q{0}, %q{[*0];0}, '[ruby-dev:31102]'
|
||||
assert_syntax_error "syntax error, unexpected ')'", %q{v0,(*,v1,) = 0}, '[ruby-dev:31104]'
|
||||
assert_equal %q{1}, %q{
|
||||
|
|
11
parse.y
11
parse.y
|
@ -573,6 +573,7 @@ static void numparam_name(struct parser_params *p, ID id);
|
|||
#define STR_NEW2(ptr) rb_enc_str_new((ptr),strlen(ptr),p->enc)
|
||||
#define STR_NEW3(ptr,len,e,func) parser_str_new(p, (ptr),(len),(e),(func),p->enc)
|
||||
#define TOK_INTERN() intern_cstr(tok(p), toklen(p), p->enc)
|
||||
#define VALID_SYMNAME_P(s, l, enc, type) (rb_enc_symname_type(s, l, enc, (1U<<(type))) == (int)(type))
|
||||
|
||||
static st_table *
|
||||
push_pvtbl(struct parser_params *p)
|
||||
|
@ -9640,7 +9641,13 @@ parse_gvar(struct parser_params *p, const enum lex_state_e last_state)
|
|||
|
||||
if (tokadd_ident(p, c)) return 0;
|
||||
SET_LEX_STATE(EXPR_END);
|
||||
tokenize_ident(p);
|
||||
if (VALID_SYMNAME_P(tok(p), toklen(p), p->enc, ID_GLOBAL)) {
|
||||
tokenize_ident(p);
|
||||
}
|
||||
else {
|
||||
compile_error(p, "`%.*s' is not allowed as a global variable name", toklen(p), tok(p));
|
||||
set_yylval_noname();
|
||||
}
|
||||
return tGVAR;
|
||||
}
|
||||
|
||||
|
@ -13661,7 +13668,7 @@ rb_reg_named_capture_assign_iter_impl(struct parser_params *p, const char *s, lo
|
|||
NODE *node, *succ;
|
||||
|
||||
if (!len) return ST_CONTINUE;
|
||||
if (rb_enc_symname_type(s, len, enc, (1U<<ID_LOCAL)) != ID_LOCAL)
|
||||
if (!VALID_SYMNAME_P(s, len, enc, ID_LOCAL))
|
||||
return ST_CONTINUE;
|
||||
|
||||
var = intern_cstr(s, len, enc);
|
||||
|
|
3
symbol.h
3
symbol.h
|
@ -109,10 +109,9 @@ is_global_name_punct(const int c)
|
|||
return (ruby_global_name_punct_bits[(c - 0x20) / 32] >> (c % 32)) & 1;
|
||||
}
|
||||
|
||||
int rb_enc_symname_type(const char *name, long len, rb_encoding *enc, unsigned int allowed_attrset);
|
||||
|
||||
RUBY_SYMBOL_EXPORT_BEGIN
|
||||
|
||||
int rb_enc_symname_type(const char *name, long len, rb_encoding *enc, unsigned int allowed_attrset);
|
||||
size_t rb_sym_immortal_count(void);
|
||||
|
||||
RUBY_SYMBOL_EXPORT_END
|
||||
|
|
|
@ -661,6 +661,7 @@ class TestParse < Test::Unit::TestCase
|
|||
assert_syntax_error(':@@1', /is not allowed/)
|
||||
assert_syntax_error(':@', /is not allowed/)
|
||||
assert_syntax_error(':@1', /is not allowed/)
|
||||
assert_syntax_error(':$01234', /is not allowed/)
|
||||
end
|
||||
|
||||
def test_parse_string
|
||||
|
@ -1478,8 +1479,8 @@ x = __ENCODING__
|
|||
end
|
||||
|
||||
def test_ungettable_gvar
|
||||
assert_syntax_error('$01234', /not valid to get/)
|
||||
assert_syntax_error('"#$01234"', /not valid to get/)
|
||||
assert_syntax_error('$01234', /not allowed/)
|
||||
assert_syntax_error('"#$01234"', /not allowed/)
|
||||
end
|
||||
|
||||
=begin
|
||||
|
|
Загрузка…
Ссылка в новой задаче