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:
parent
22da5d71ea
commit
c990b3c41a
3 changed files with 12 additions and 2 deletions
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);
|
c = scan_hex(p->lex.pcur, 2, numlen);
|
||||||
if (!*numlen) {
|
if (!*numlen) {
|
||||||
p->lex.ptok = p->lex.pcur;
|
|
||||||
yyerror0("invalid hex escape");
|
yyerror0("invalid hex escape");
|
||||||
|
token_flush(p);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
p->lex.pcur += *numlen;
|
p->lex.pcur += *numlen;
|
||||||
|
|
|
@ -976,4 +976,14 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase
|
||||||
assert_match /Invalid char/, err[1]
|
assert_match /Invalid char/, err[1]
|
||||||
assert_equal "\e", err[2]
|
assert_equal "\e", err[2]
|
||||||
end
|
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
|
end if ripper_test
|
||||||
|
|
|
@ -513,7 +513,7 @@ class TestParse < Test::Unit::TestCase
|
||||||
mesg = 'from the backslash through the invalid char'
|
mesg = 'from the backslash through the invalid char'
|
||||||
|
|
||||||
e = assert_syntax_error('"\xg1"', /hex escape/)
|
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')
|
e = assert_syntax_error('"\u{1234"', 'unterminated Unicode escape')
|
||||||
assert_equal(' ^', e.message.lines.last, mesg)
|
assert_equal(' ^', e.message.lines.last, mesg)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue