Repository navigation
fix(env): quote legacy ENV values that contain spaces - #74
Merged
Merged
Conversation
Signed-off-by: Ryo Kusnadi <ryokusnadi@gmail.com>
4 tasks done
Owner
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.
Problem
Formatting a legacy
ENVline whose value has spaces gives a Dockerfile that doesn't parse, sodockerfmt --writebreaks the build.How it happens: any
ENV KEY some valueline (legacy form, everything after the key is the value) with more than one word, e.g.JAVA_OPTS.Steps to reproduce
Run
dockerfmt Dockerfile.Expected:
ENV JAVA_OPTS="-Xms256m -Xmx512m"Actual:
ENV JAVA_OPTS=-Xms256m -Xmx512m, which fails with "can't find = in "-Xmx512m"".Cause
formatEnvinlib/format.gojoined key and value with=and never quoted.Fix
New
formatLegacyEnv: no whitespace in the value givesKEY=valueas before; an already single-quoted value is kept as is; otherwise the value is wrapped in double quotes. If a spaced value also has quotes or backslashes, I keep the legacy form, since re-quoting would change the value (and the legacy form is valid).Scope
LABELandARGgo throughformatBasic, which keeps their text, so they aren't converted and need no change.Testing
Added cases to
TestPerDirective(spaces, tabs/repeated spaces,$VAR, already quoted, embedded quotes). Without the fix 4 of them fail, e.g. actualENV JAVA_OPTS=-Xms256m -Xmx512m; with itgo test ./lib/ .andgo vet ./lib/pass. Not run: the JS/wasm build.Environment: fix/quote-legacy-env-values @ d775b50, go1.27.1, darwin/arm64
Fixes #69