[Bug #20784] Fix incomplete character syntax followed by EOF

This commit is contained in:
tompng 2024-10-05 15:18:45 +09:00 committed by Nobuyoshi Nakada
parent e939f28cc9
commit 6743e6285a
Notes: git 2024-10-05 06:59:19 +00:00
2 changed files with 5 additions and 1 deletions

View file

@ -10118,7 +10118,7 @@ parse_qmark(struct parser_params *p, int space_seen)
enc = rb_utf8_encoding();
tokadd_utf8(p, &enc, -1, 0, 0);
}
else if (!ISASCII(c = peekc(p))) {
else if (!ISASCII(c = peekc(p)) && c != -1) {
nextc(p);
if (tokadd_mbchar(p, c) == -1) return 0;
}

View file

@ -951,6 +951,10 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase
assert_equal ["?\\u{41}"],
scan('CHAR', "?\\u{41}")
err = nil
assert_equal [], scan('CHAR', '?\\') {|*e| err = e}
assert_equal([:on_parse_error, "Invalid escape character syntax", "?\\"], err)
err = nil
assert_equal [], scan('CHAR', '?\\M ') {|*e| err = e}
assert_equal([:on_parse_error, "Invalid escape character syntax", "?\\M "], err)