Skip to content

Respect heredoc and continuation boundaries - #152

Open
tamird wants to merge 2 commits into
containerbuildsystem:masterfrom
tamird:codex/heredoc-instruction-boundaries
Open

tamird wants to merge 2 commits into
containerbuildsystem:masterfrom
tamird:codex/heredoc-instruction-boundaries

Conversation

@tamird

@tamird tamird commented Sep 30, 2026 •

Copy link
Copy Markdown

The parser mistakes FROM text inside a RUN heredoc for another stage, and replacing RUN leaves its body behind. It also swallows a real instruction after a line ending in consecutive escape characters.

Include each heredoc’s body and terminator in its returned value and line range, so edits handle the complete block. A terminal escape continues an instruction only when it is not preceded by another escape. Cached reads preserve physical line boundaries, and reading an unterminated heredoc raises ValueError.

Fixes #145.

Codex-assisted implementation with delegated independent review.

Heredoc payload lines currently become separate instructions. A FROM
inside a RUN body changes parent_images, and replacing the RUN leaves
its body behind.

Consume bodies and terminators with their RUN, COPY, or ADD header,
including ONBUILD instructions. Preserve body content and physical line
bounds, and include the bodies in value and JSON output. Recognize
quoted and multiple delimiters using Docker's frontend rules [1].
Unterminated bodies fail when reading structure, before edits that
depend on that parse write.

Reuse WordSplitter with optional separator preservation so operator
spacing remains distinguishable without changing existing callers.
Align cached line splitting with file reads so literal carriage returns
in bodies do not change parsing or edit boundaries when caching is on.

Fixes containerbuildsystem#145.

Codex-assisted implementation with delegated independent review.

[1]: https://docs.docker.com/reference/dockerfile/#here-documents

Signed-off-by: Tamir Duberstein <tamird@gmail.com>
Doubled terminal escape characters currently absorb the next Dockerfile
instruction and lose a literal character from the value.

Use Docker’s continuation rule for both instruction boundaries and value
normalization, including the escape directive. Heredoc bodies then start
at the same boundary as the builder.

Signed-off-by: Tamir Duberstein <tamird@gmail.com>
@tamird tamird changed the title Parse heredoc bodies with their instructions Respect heredoc and continuation boundaries Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support heredocs

1 participant