fix: a heredoc closing marker may carry trailing whitespace (#343) - #349
Open
livingstaccato wants to merge 1 commit into
Open
fix: a heredoc closing marker may carry trailing whitespace (#343)#349livingstaccato wants to merge 1 commit into
livingstaccato wants to merge 1 commit into
Conversation
…n#343) The spec puts the delimiter "alone on its own line", and Terraform's scanner ends the heredoc at a line holding the word and nothing else that matters -- trailing spaces and tabs included. Both terminals required the newline to follow the word immediately, so `EOF ` was not a marker: the heredoc ran on, swallowed the rest of the file, and the parse failed with an error pointing somewhere else entirely. Trailing whitespace is invisible, survives copy-paste, and is left by editors that do not trim it, so a file someone has been running through Terraform for months could fail here for a reason nothing in the message suggests. Only whitespace: `EOFX` and `EOF x` are still body text, which OpenTofu agrees with -- it reads `<<EOF\nEOF x\nbody\nEOF \n` as "EOF x\nbody\n" and closes at the last line.
Contributor
Author
|
Please hold off on merging this one for now — I want to do another review pass over it before it goes in. Opened as a draft for that reason; I will mark it ready and say so here once I am done. |
livingstaccato
marked this pull request as ready for review
September 3, 2026 02:01
Contributor
Author
|
Review pass done, so the hold above no longer applies — this is ready for review now. Rebased on current 🤖 Drafted with Claude Code. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #343.
What
The spec puts the delimiter "alone on its own line", and Terraform's scanner ends the heredoc at a line holding the word and nothing else that matters — trailing spaces and tabs included. Both heredoc terminals required the newline to follow the word immediately:
So
EOFwas not a marker at all. The heredoc ran on, swallowed the rest of the file, and the parse failed with an error pointing somewhere else entirely.OpenTofu v1.12.5 reads the same file as
a = "body\n",b = 1.Why it matters more than it looks
Trailing whitespace is invisible. It survives copy-paste, it is left behind by editors that do not trim it, and it is exactly the kind of thing nobody inspects — so a file someone has been running through Terraform for months can fail here, with a message that names a line far from the real one.
What is still body text
Only whitespace is permitted after the word.
EOFXandEOF xremain content, and OpenTofu agrees: it readsas
"EOF x\nbody\n", closing at the last line rather than the first.The change is
\s*(?P=heredoc)\r?\n→\s*(?P=heredoc)[ \t]*\r?\nin bothHEREDOC_TEMPLATEandHEREDOC_TEMPLATE_TRIM, with eleven tests covering the forms that close and the two that do not, plus the indented and CRLF cases that already worked.Merging
This one is independent: it touches
hcl2/hcl2.larkand nothing else any other open pull request of mine changes, so it can land in any order.This pull request, and the investigation behind it, were produced by an AI assistant (Claude) working on behalf of the author. Please review with that provenance in mind.