@@ -9605,15 +9605,23 @@ lex_embdoc(pm_parser_t *parser) {
9605
9605
pm_comment_t *comment = parser_comment(parser, PM_COMMENT_EMBDOC);
9606
9606
if (comment == NULL) return PM_TOKEN_EOF;
9607
9607
9608
- // Now, loop until we find the end of the embedded documentation or the end of
9609
- // the file.
9608
+ // Now, loop until we find the end of the embedded documentation or the end
9609
+ // of the file.
9610
9610
while (parser->current.end + 4 <= parser->end) {
9611
9611
parser->current.start = parser->current.end;
9612
9612
9613
- // If we've hit the end of the embedded documentation then we'll return that
9614
- // token here.
9615
- if (memcmp(parser->current.end, "=end", 4) == 0 &&
9616
- (parser->current.end + 4 == parser->end || pm_char_is_whitespace(parser->current.end[4]))) {
9613
+ // If we've hit the end of the embedded documentation then we'll return
9614
+ // that token here.
9615
+ if (
9616
+ (memcmp(parser->current.end, "=end", 4) == 0) &&
9617
+ (
9618
+ (parser->current.end + 4 == parser->end) || // end of file
9619
+ pm_char_is_whitespace(parser->current.end[4]) || // whitespace
9620
+ (parser->current.end[4] == '\0') || // NUL or end of script
9621
+ (parser->current.end[4] == '\004') || // ^D
9622
+ (parser->current.end[4] == '\032') // ^Z
9623
+ )
9624
+ ) {
9617
9625
const uint8_t *newline = next_newline(parser->current.end, parser->end - parser->current.end);
9618
9626
9619
9627
if (newline == NULL) {
@@ -10425,9 +10433,13 @@ parser_lex(pm_parser_t *parser) {
10425
10433
10426
10434
// = => =~ == === =begin
10427
10435
case '=':
10428
- if (current_token_starts_line(parser) && (parser->current.end + 5 <= parser->end) && memcmp(parser->current.end, "begin", 5) == 0 && pm_char_is_whitespace(peek_offset(parser, 5))) {
10436
+ if (
10437
+ current_token_starts_line(parser) &&
10438
+ (parser->current.end + 5 <= parser->end) &&
10439
+ memcmp(parser->current.end, "begin", 5) == 0 &&
10440
+ (pm_char_is_whitespace(peek_offset(parser, 5)) || (peek_offset(parser, 5) == '\0'))
10441
+ ) {
10429
10442
pm_token_type_t type = lex_embdoc(parser);
10430
-
10431
10443
if (type == PM_TOKEN_EOF) {
10432
10444
LEX(type);
10433
10445
}
0 commit comments