[Bug #19736] Recover after unterminated interpolation

This commit is contained in:
Nobuyoshi Nakada 2023-06-20 20:10:46 +09:00
parent 49b83b73ef
commit 6be402e172
No known key found for this signature in database
GPG Key ID: 7CD2805BFA3770C6
Notes: git 2023-06-20 12:25:00 +00:00
3 changed files with 23 additions and 1 deletions

View File

@ -5331,7 +5331,7 @@ string_content : tSTRING_CONTENT
$<num>$ = p->heredoc_indent; $<num>$ = p->heredoc_indent;
p->heredoc_indent = 0; p->heredoc_indent = 0;
} }
compstmt tSTRING_DEND compstmt string_dend
{ {
COND_POP(); COND_POP();
CMDARG_POP(); CMDARG_POP();
@ -5348,6 +5348,10 @@ string_content : tSTRING_CONTENT
} }
; ;
string_dend : tSTRING_DEND
| END_OF_INPUT
;
string_dvar : tGVAR string_dvar : tGVAR
{ {
/*%%%*/ /*%%%*/

View File

@ -264,4 +264,13 @@ world"
CODE CODE
assert_equal(code, Ripper.tokenize(code).join(""), bug) assert_equal(code, Ripper.tokenize(code).join(""), bug)
end end
def test_heredoc_unterminated_interpolation
code = <<~'HEREDOC'
<<A+1
#{
HEREDOC
assert_include(Ripper.tokenize(code).join(""), "+1")
end
end end

View File

@ -1121,6 +1121,15 @@ x = __ENCODING__
assert_equal v1, v3 assert_equal v1, v3
end 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 def test_unexpected_token_error
assert_syntax_error('"x"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', /unexpected/) assert_syntax_error('"x"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', /unexpected/)
end end