Skip to content

Commit

Permalink
handle missing HEREDOC endline at start of heredoc
Browse files Browse the repository at this point in the history
  • Loading branch information
HParker authored and kddnewton committed Aug 18, 2023
1 parent 37445b9 commit 7b72493
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/yarp.c
Original file line number Diff line number Diff line change
Expand Up @@ -5653,13 +5653,23 @@ parser_lex(yp_parser_t *parser) {
break;
case '\\':
if (peek_at(parser, 1) == '\n') {
yp_newline_list_append(&parser->newline_list, parser->current.end + 1);
parser->current.end += 2;
space_seen = true;
} else if (parser->current.end + 2 < parser->end && peek_at(parser, 1) == '\r' && peek_at(parser, 2) == '\n') {
yp_newline_list_append(&parser->newline_list, parser->current.end + 2);
parser->current.end += 3;
space_seen = true;
if (parser->heredoc_end) {
parser->current.end = parser->heredoc_end;
parser->heredoc_end = NULL;
} else {
yp_newline_list_append(&parser->newline_list, parser->current.end + 1);
parser->current.end += 2;
space_seen = true;
}
} else if (peek_at(parser, 1) == '\r' && peek_at(parser, 2) == '\n') {
if (parser->heredoc_end) {
parser->current.end = parser->heredoc_end;
parser->heredoc_end = NULL;
} else {
yp_newline_list_append(&parser->newline_list, parser->current.end + 2);
parser->current.end += 3;
space_seen = true;
}
} else if (yp_char_is_inline_whitespace(*parser->current.end)) {
parser->current.end += 2;
} else {
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/heredoc_with_escaped_newline_at_start.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<<-TARGET.gsub /^\s{/, ''\
TARGET


<<-TARGET.gsub /^\s{/, ''\
TARGET

45 changes: 45 additions & 0 deletions test/snapshots/heredoc_with_escaped_newline_at_start.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7b72493

Please sign in to comment.