Skip to content

Commit 6743e62

Browse files
tompngnobu
authored andcommitted
[Bug #20784] Fix incomplete character syntax followed by EOF
1 parent e939f28 commit 6743e62

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

parse.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10118,7 +10118,7 @@ parse_qmark(struct parser_params *p, int space_seen)
1011810118
enc = rb_utf8_encoding();
1011910119
tokadd_utf8(p, &enc, -1, 0, 0);
1012010120
}
10121-
else if (!ISASCII(c = peekc(p))) {
10121+
else if (!ISASCII(c = peekc(p)) && c != -1) {
1012210122
nextc(p);
1012310123
if (tokadd_mbchar(p, c) == -1) return 0;
1012410124
}

test/ripper/test_scanner_events.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,10 @@ def test_CHAR
951951
assert_equal ["?\\u{41}"],
952952
scan('CHAR', "?\\u{41}")
953953

954+
err = nil
955+
assert_equal [], scan('CHAR', '?\\') {|*e| err = e}
956+
assert_equal([:on_parse_error, "Invalid escape character syntax", "?\\"], err)
957+
954958
err = nil
955959
assert_equal [], scan('CHAR', '?\\M ') {|*e| err = e}
956960
assert_equal([:on_parse_error, "Invalid escape character syntax", "?\\M "], err)

0 commit comments

Comments
 (0)