Keep quoted sections intact when pretty printing shell form arguments - #117
Merged
Conversation
prettyPrintArguments split the argument text with Text.words, so a quoted
section was cut into words like any other text. Two things followed. An
&& written inside quotes matched the helper that inserts a line break,
and the spacing inside the quotes was rewritten when the words were
joined back with a single space each.
RUN grep -F 'cd dir && ./run.sh ' /opt/Makefile
came back out as
RUN grep -F 'cd dir \
&& ./run.sh ' /opt/Makefile
which is a different command, and
RUN echo 'a b'
came back as RUN echo 'a b'.
Split on whitespace only outside quotes, so a quoted section stays part
of the word it belongs to. An escaped character is kept with the word as
well, since an escaped space does not end one. Words are still joined
with a single space, so nothing changes for unquoted text and a real &&
still breaks the line.
Fixes hadolint#90
Fixes hadolint#57
Contributor
Author
|
@m-ildefons a short nudge — this has been green and conflict-free for a week. It closes #90 and #57 together, since the same One thing worth flagging given #116 is open: this touches |
Member
m-ildefons
approved these changes
Aug 24, 2026
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 #90.
Fixes #57 — the same
Text.wordscall causes both, so one change closes them together.What happens
prettyPrintArgumentssplits the argument text withText.words, so a quoted section is cut into words like any other text. Two things follow: an&&written inside quotes matches the helper that inserts a line break, and the spacing inside the quotes is rewritten when the words are joined back with a single space each.On
master,parseTextfollowed byprettyPrintturns thisinto this
The first one is no longer the same command:
grepgetscd dirand the remainder becomes a separate stage of the shell line.The change
Split on whitespace only outside quotes, so a quoted section stays part of the word it belongs to. An escaped character is kept with its word as well, since an escaped space does not end one. Words are still joined with a single space, so nothing changes for unquoted text.
Same two lines after the change, plus a control that a real
&&still breaks:Tests
Three cases added to the
pretty print RUNgroup: the two above, plus the control. The first two fail onmaster—RUN grep -F 'cd dir \\n && ./run.sh ' ...andRUN echo 'a b'— and pass with the change; the control passes both before and after.cabal testgoes from 309 examples / 2 failures to 309 examples / 0 failures on GHC 9.8.4.