Skip to content

Commit

Permalink
[ruby/prism] Fix parsing unterminated empty string "
Browse files Browse the repository at this point in the history
  • Loading branch information
makenowjust authored and matzbot committed Dec 11, 2023
1 parent a860e36 commit 48cb70f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion prism/prism.c
Expand Up @@ -13520,7 +13520,8 @@ parse_strings(pm_parser_t *parser, pm_node_t *current) {
pm_token_t opening = parser->current;
parser_lex(parser);

if (accept1(parser, PM_TOKEN_STRING_END)) {
if (match2(parser, PM_TOKEN_STRING_END, PM_TOKEN_EOF)) {
expect1(parser, PM_TOKEN_STRING_END, PM_ERR_STRING_LITERAL_TERM);
// If we get here, then we have an end immediately after a
// start. In that case we'll create an empty content token and
// return an uninterpolated string.
Expand Down
9 changes: 9 additions & 0 deletions test/prism/errors_test.rb
Expand Up @@ -164,6 +164,15 @@ def test_unterminated_string
assert_equal expr.closing, ""
end

def test_unterminated_empty_string
expr = expression('"')
assert_errors expr, '"', [
["expected a closing delimiter for the string literal", 1..1]
]
assert_equal expr.unescaped, ""
assert_equal expr.closing, ""
end

def test_incomplete_instance_var_string
assert_errors expression('%@#@@#'), '%@#@@#', [
["incomplete instance variable", 4..5],
Expand Down

0 comments on commit 48cb70f

Please sign in to comment.