зеркало из https://github.com/github/ruby.git
Fix the error token on "invalid hex escape"
* parse.y (tok_hex): flush token after dispatching the "invalid hex escape" parse error.
This commit is contained in:
Родитель
22da5d71ea
Коммит
c990b3c41a
2
parse.y
2
parse.y
|
@ -6133,8 +6133,8 @@ tok_hex(struct parser_params *p, size_t *numlen)
|
|||
|
||||
c = scan_hex(p->lex.pcur, 2, numlen);
|
||||
if (!*numlen) {
|
||||
p->lex.ptok = p->lex.pcur;
|
||||
yyerror0("invalid hex escape");
|
||||
token_flush(p);
|
||||
return 0;
|
||||
}
|
||||
p->lex.pcur += *numlen;
|
||||
|
|
|
@ -976,4 +976,14 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase
|
|||
assert_match /Invalid char/, err[1]
|
||||
assert_equal "\e", err[2]
|
||||
end
|
||||
|
||||
def test_invalid_hex_escape
|
||||
err = nil
|
||||
assert_equal ['U'], scan('tstring_content', '"\\xU"') {|*e| err = e}
|
||||
assert_equal [:on_parse_error, "invalid hex escape", "\\x"], err
|
||||
|
||||
err = nil
|
||||
assert_equal ['U'], scan('tstring_content', '/\\xU/') {|*e| err = e}
|
||||
assert_equal [:on_parse_error, "invalid hex escape", "\\x"], err
|
||||
end
|
||||
end if ripper_test
|
||||
|
|
|
@ -513,7 +513,7 @@ class TestParse < Test::Unit::TestCase
|
|||
mesg = 'from the backslash through the invalid char'
|
||||
|
||||
e = assert_syntax_error('"\xg1"', /hex escape/)
|
||||
assert_equal(' ^', e.message.lines.last, mesg)
|
||||
assert_equal(' ^~', e.message.lines.last, mesg)
|
||||
|
||||
e = assert_syntax_error('"\u{1234"', 'unterminated Unicode escape')
|
||||
assert_equal(' ^', e.message.lines.last, mesg)
|
||||
|
|
Загрузка…
Ссылка в новой задаче