Skip to content

Commit

Permalink
[Bug #19736] Recover after unterminated interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Jun 20, 2023
1 parent 49b83b7 commit 6be402e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion parse.y
Expand Up @@ -5331,7 +5331,7 @@ string_content : tSTRING_CONTENT
$<num>$ = p->heredoc_indent;
p->heredoc_indent = 0;
}
compstmt tSTRING_DEND
compstmt string_dend
{
COND_POP();
CMDARG_POP();
Expand All @@ -5348,6 +5348,10 @@ string_content : tSTRING_CONTENT
}
;

string_dend : tSTRING_DEND
| END_OF_INPUT
;

string_dvar : tGVAR
{
/*%%%*/
Expand Down
9 changes: 9 additions & 0 deletions test/ripper/test_lexer.rb
Expand Up @@ -264,4 +264,13 @@ def test_heredoc_inside_block_param
CODE
assert_equal(code, Ripper.tokenize(code).join(""), bug)
end

def test_heredoc_unterminated_interpolation
code = <<~'HEREDOC'
<<A+1
#{
HEREDOC

assert_include(Ripper.tokenize(code).join(""), "+1")
end
end
9 changes: 9 additions & 0 deletions test/ruby/test_parse.rb
Expand Up @@ -1121,6 +1121,15 @@ def test_heredoc_interpolation
assert_equal v1, v3
end

def test_heredoc_unterminated_interpolation
code = <<~'HEREDOC'
<<A+1
#{
HEREDOC

assert_syntax_error(code, /can't find string "A"/)
end

def test_unexpected_token_error
assert_syntax_error('"x"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', /unexpected/)
end
Expand Down

0 comments on commit 6be402e

Please sign in to comment.