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

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:
Nobuyoshi Nakada 2019-06-03 14:56:42 +09:00
parent 22da5d71ea
commit c990b3c41a
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60
3 changed files with 12 additions and 2 deletions

View file

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

View file

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

View file

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