[ruby-core:127560] [Ruby Bug#22561] parse.y rejects empty heredocs terminated by `\r\n` (`<<""\r\n\r\n`)
Issue #22561 has been reported by steviejj (Steven Johnstone). ---------------------------------------- Bug #22561: parse.y rejects empty heredocs terminated by `\r\n` (`<<""\r\n\r\n`) https://bugs.ruby-lang.org/issues/22561 * Author: steviejj (Steven Johnstone) * Status: Open * ruby -v: ruby 4.0.9 (2026-10-23 revision 3e93b23afc) +PRISM [arm64-darwin27] * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- CRuby `parse.y` rejects empty-delimiter heredocs (`<<''`, `<<""`, `<<-''`, `<<~''`) whenever the closing blank terminator line uses `\r\n` (`CRLF`), raising `SyntaxError: can't find string "" anywhere before EOF`—even though `parse.y` accepts non-empty heredocs with `\r\n` (`<<'A'\r\nA\r\n`) as well as empty heredocs with `\n` (`<<''\n\n`). Prism accepts empty heredocs with `\r\n` cleanly. Tested on CRuby `4.0.9` (`--parser=parse.y` vs `--parser=prism`): ```sh # Empty heredoc with CRLF line endings: ruby --parser=prism -e "$(printf 'p <<""\r\n\r\n')" # exits 0, prints "" ruby --parser=parse.y -e "$(printf 'p <<""\r\n\r\n')" # exits 1: can't find string "" anywhere before EOF # Mixed LF opening line + CRLF closing line, and indented variants: for open in "<<''" '<<""' "<<-''" "<<~''"; do printf "p %s\r\n\r\n" "$open" | ruby --parser=prism printf "p %s\r\n\r\n" "$open" | ruby --parser=parse.y done # Non-empty heredoc with CRLF works in both: ruby --parser=parse.y -e "$(printf "p <<'A'\r\nA\r\n")" # exits 0, prints "" -- https://bugs.ruby-lang.org/
participants (1)
-
steviejj (Steven Johnstone)