Skip to content

Commit

Permalink
[ruby/prism] Fix closing loc for string literals
Browse files Browse the repository at this point in the history
  • Loading branch information
makenowjust authored and matzbot committed Dec 6, 2023
1 parent a57186b commit cbb941f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
6 changes: 3 additions & 3 deletions prism/prism.c
Expand Up @@ -13580,7 +13580,7 @@ parse_strings(pm_parser_t *parser, pm_node_t *current) {
node = (pm_node_t *) pm_symbol_node_create_unescaped(parser, &opening, &content, &parser->previous, &unescaped);
} else if (match1(parser, PM_TOKEN_EOF)) {
pm_parser_err_token(parser, &opening, PM_ERR_STRING_LITERAL_TERM);
node = (pm_node_t *) pm_string_node_create_unescaped(parser, &opening, &content, &parser->previous, &unescaped);
node = (pm_node_t *) pm_string_node_create_unescaped(parser, &opening, &content, &parser->current, &unescaped);
} else {
expect1(parser, PM_TOKEN_STRING_END, PM_ERR_STRING_LITERAL_TERM);
node = (pm_node_t *) pm_string_node_create_unescaped(parser, &opening, &content, &parser->previous, &unescaped);
Expand Down Expand Up @@ -13621,7 +13621,7 @@ parse_strings(pm_parser_t *parser, pm_node_t *current) {
node = (pm_node_t *) pm_interpolated_symbol_node_create(parser, &opening, &parts, &parser->previous);
} else if (match1(parser, PM_TOKEN_EOF)) {
pm_parser_err_token(parser, &opening, PM_ERR_STRING_INTERPOLATED_TERM);
node = (pm_node_t *) pm_interpolated_string_node_create(parser, &opening, &parts, &parser->previous);
node = (pm_node_t *) pm_interpolated_string_node_create(parser, &opening, &parts, &parser->current);
} else {
expect1(parser, PM_TOKEN_STRING_END, PM_ERR_STRING_INTERPOLATED_TERM);
node = (pm_node_t *) pm_interpolated_string_node_create(parser, &opening, &parts, &parser->previous);
Expand All @@ -13644,7 +13644,7 @@ parse_strings(pm_parser_t *parser, pm_node_t *current) {
node = (pm_node_t *) pm_interpolated_symbol_node_create(parser, &opening, &parts, &parser->previous);
} else if (match1(parser, PM_TOKEN_EOF)) {
pm_parser_err_token(parser, &opening, PM_ERR_STRING_INTERPOLATED_TERM);
node = (pm_node_t *) pm_interpolated_string_node_create(parser, &opening, &parts, &parser->previous);
node = (pm_node_t *) pm_interpolated_string_node_create(parser, &opening, &parts, &parser->current);
} else {
expect1(parser, PM_TOKEN_STRING_END, PM_ERR_STRING_INTERPOLATED_TERM);
node = (pm_node_t *) pm_interpolated_string_node_create(parser, &opening, &parts, &parser->previous);
Expand Down
16 changes: 14 additions & 2 deletions test/prism/errors_test.rb
Expand Up @@ -146,10 +146,22 @@ def test_unterminated_xstring
]
end

def test_unterminated_string
assert_errors expression('"hello'), '"hello', [
def test_unterminated_interpolated_string
expr = expression('"hello')
assert_errors expr, '"hello', [
["expected a closing delimiter for the interpolated string", 0..1]
]
assert_equal expr.parts[0].unescaped, "hello"
assert_equal expr.closing, ""
end

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

def test_incomplete_instance_var_string
Expand Down

0 comments on commit cbb941f

Please sign in to comment.