Skip to content

Commit 8280e57

Browse files
committed
Fix parsing unterminated empty string "
Fix #2034
1 parent 53827c4 commit 8280e57

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/prism.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13520,7 +13520,8 @@ parse_strings(pm_parser_t *parser, pm_node_t *current) {
1352013520
pm_token_t opening = parser->current;
1352113521
parser_lex(parser);
1352213522

13523-
if (accept1(parser, PM_TOKEN_STRING_END)) {
13523+
if (match2(parser, PM_TOKEN_STRING_END, PM_TOKEN_EOF)) {
13524+
expect1(parser, PM_TOKEN_STRING_END, PM_ERR_STRING_LITERAL_TERM);
1352413525
// If we get here, then we have an end immediately after a
1352513526
// start. In that case we'll create an empty content token and
1352613527
// return an uninterpolated string.

test/prism/errors_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,15 @@ def test_unterminated_string
164164
assert_equal expr.closing, ""
165165
end
166166

167+
def test_unterminated_empty_string
168+
expr = expression('"')
169+
assert_errors expr, '"', [
170+
["expected a closing delimiter for the string literal", 1..1]
171+
]
172+
assert_equal expr.unescaped, ""
173+
assert_equal expr.closing, ""
174+
end
175+
167176
def test_incomplete_instance_var_string
168177
assert_errors expression('%@#@@#'), '%@#@@#', [
169178
["incomplete instance variable", 4..5],

0 commit comments

Comments
 (0)