parse.y: fix token

* parse.y (parser_parse_string): return proper token tREGEXP_END
  at unterminated regexp.  [Bug #13363]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59196 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-06-28 06:13:00 +00:00
parent 957d1ccdf9
commit f78d92c5ca
2 changed files with 15 additions and 5 deletions

12
parse.y
View File

@ -5461,7 +5461,7 @@ rb_parser_compile_file_path(VALUE vparser, VALUE fname, VALUE file, int start)
#define STR_FUNC_SYMBOL 0x10 #define STR_FUNC_SYMBOL 0x10
#define STR_FUNC_INDENT 0x20 #define STR_FUNC_INDENT 0x20
#define STR_FUNC_LABEL 0x40 #define STR_FUNC_LABEL 0x40
#define STR_TERM_END -1 #define STR_FUNC_TERM 0x8000
enum string_type { enum string_type {
str_label = STR_FUNC_LABEL, str_label = STR_FUNC_LABEL,
@ -6237,7 +6237,9 @@ parser_parse_string(struct parser_params *parser, NODE *quote)
int c, space = 0; int c, space = 0;
rb_encoding *enc = current_enc; rb_encoding *enc = current_enc;
if (term == STR_TERM_END) return tSTRING_END; if (func & STR_FUNC_TERM) {
return func & STR_FUNC_REGEXP ? tREGEXP_END : tSTRING_END;
}
c = nextc(); c = nextc();
if ((func & STR_FUNC_QWORDS) && ISSPACE(c)) { if ((func & STR_FUNC_QWORDS) && ISSPACE(c)) {
do {c = nextc();} while (ISSPACE(c)); do {c = nextc();} while (ISSPACE(c));
@ -6245,7 +6247,7 @@ parser_parse_string(struct parser_params *parser, NODE *quote)
} }
if (c == term && !quote->nd_nest) { if (c == term && !quote->nd_nest) {
if (func & STR_FUNC_QWORDS) { if (func & STR_FUNC_QWORDS) {
quote->u2.id = STR_TERM_END; quote->nd_func |= STR_FUNC_TERM;
return ' '; return ' ';
} }
return parser_string_term(parser, func); return parser_string_term(parser, func);
@ -6271,7 +6273,7 @@ parser_parse_string(struct parser_params *parser, NODE *quote)
else { else {
compile_error(PARSER_ARG "unterminated string meets end of file"); compile_error(PARSER_ARG "unterminated string meets end of file");
} }
quote->u2.id = STR_TERM_END; quote->nd_func |= STR_FUNC_TERM;
} }
} }
@ -6704,7 +6706,7 @@ parser_here_document(struct parser_params *parser, NODE *here)
yylval.val, str); yylval.val, str);
#endif #endif
heredoc_restore(lex_strterm); heredoc_restore(lex_strterm);
lex_strterm = NEW_STRTERM(func, STR_TERM_END, 0); lex_strterm = NEW_STRTERM(func | STR_FUNC_TERM, 0, 0);
set_yylval_str(str); set_yylval_str(str);
return tSTRING_CONTENT; return tSTRING_CONTENT;
} }

View File

@ -1022,6 +1022,14 @@ x = __ENCODING__
assert_operator(line, :end_with?, "...\n") assert_operator(line, :end_with?, "...\n")
end end
def test_unterminated_regexp_error
e = assert_raise(SyntaxError) do
eval("/x")
end.message
assert_match(/unterminated regexp meets end of file/, e)
assert_not_match(/unexpected tSTRING_END/, e)
end
=begin =begin
def test_past_scope_variable def test_past_scope_variable
assert_warning(/past scope/) {catch {|tag| eval("BEGIN{throw tag}; tap {a = 1}; a")}} assert_warning(/past scope/) {catch {|tag| eval("BEGIN{throw tag}; tap {a = 1}; a")}}