Skip to content

Commit

Permalink
Merge pull request #1278 from HParker/fix-newline-missing-at-start-of…
Browse files Browse the repository at this point in the history
…-heredoc

handle missing HEREDOC endline at start of heredoc
  • Loading branch information
kddnewton authored Aug 18, 2023
2 parents 37445b9 + 7b72493 commit 2cb4cb0
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 2cb4cb0

Please sign in to comment.