Skip to content

Commit

Permalink
Do not make an incomplete escape a valid char
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed May 27, 2019
1 parent c40003d commit b4365e7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions parse.y
Expand Up @@ -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;
}
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion test/ripper/test_scanner_events.rb
Expand Up @@ -938,7 +938,7 @@ def test_CHAR

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

Expand Down

0 comments on commit b4365e7

Please sign in to comment.