Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- Fix an error when using heredoc with non-word delimiters #987

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/parser/lexer/literal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def delimiter?(delimiter)
# E
# because there are not enough leading spaces in the closing delimiter.
delimiter.end_with?(@end_delim) &&
delimiter.sub(/#{@end_delim}\z/, '').bytes.all? { |c| c == SPACE }
delimiter.sub(/#{Regexp.escape(@end_delim)}\z/, '').bytes.all? { |c| c == SPACE }
elsif @indent
@end_delim == delimiter.lstrip
else
Expand Down
10 changes: 10 additions & 0 deletions test/test_lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,16 @@ def test_heredoc_one_character
:tNL, nil, [7, 8])
end

def test_heredoc_plus_character
assert_scanned("a = <<'+'\nABCDEF\n+\n",
:tIDENTIFIER, "a", [0, 1],
:tEQL, "=", [2, 3],
:tSTRING_BEG, "<<\'", [4, 9],
:tSTRING_CONTENT, "ABCDEF\n", [10, 17],
:tSTRING_END, "+", [17, 18],
:tNL, nil, [9, 10])
end

def test_heredoc_cr
assert_scanned("a = <<E\r\r\nABCDEF\r\r\nE\r\r\r\n",
:tIDENTIFIER, "a", [0, 1],
Expand Down