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

Do not make an incomplete escape a valid char

This commit is contained in:
Nobuyoshi Nakada 2019-05-27 19:58:15 +09:00
parent c40003da25
commit b4365e75fd
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60
2 changed files with 5 additions and 5 deletions

View file

@ -6211,7 +6211,7 @@ tokadd_utf8(struct parser_params *p, rb_encoding **encp,
if (c != close_brace) {
unterminated:
literal_flush(p, p->lex.pcur);
token_flush(p);
yyerror0("unterminated Unicode escape");
return;
}
@ -6221,11 +6221,10 @@ tokadd_utf8(struct parser_params *p, rb_encoding **encp,
}
else { /* handle \uxxxx form */
if (!tokadd_codepoint(p, encp, regexp_literal, FALSE)) {
token_flush(p);
return;
}
}
return;
}
#define ESCAPE_CONTROL 1
@ -6312,7 +6311,7 @@ read_escape(struct parser_params *p, int flags, rb_encoding **encp)
eof:
case -1:
yyerror0("Invalid escape character syntax");
pushback(p, c);
token_flush(p);
return '\0';
default:
@ -6391,6 +6390,7 @@ tokadd_escape(struct parser_params *p, rb_encoding **encp)
eof:
case -1:
yyerror0("Invalid escape character syntax");
token_flush(p);
return -1;
default:

View file

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