Strip matching quotes from --env-file values#6805
Open
veeceey wants to merge 1 commit intodocker:masterfrom
Open
Strip matching quotes from --env-file values#6805veeceey wants to merge 1 commit intodocker:masterfrom
veeceey wants to merge 1 commit intodocker:masterfrom
Conversation
When using a .env file with both `source` on Linux and `docker run --env-file`, quoted values like FOO="bar" would include the literal quotes in Docker, breaking compatibility. This strips matching outer quotes (single or double) from values, consistent with how shells handle sourced env files and matching docker compose behavior. Signed-off-by: Varun Chawla <varun_6april@hotmail.com>
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.
- What I did
Fixes #3630
I ran into this exact issue at work -- we share a single
.envfile between our local dev setup (where wesourceit) and our Docker containers (via--env-file). Any value with spaces in it needs quotes forsourceto work, but Docker was treating the quotes as literal characters. Drove me crazy for a while before I realized what was happening.This adds quote stripping for values in
--env-fileparsing, matching how shells handle sourced files and howdocker composealready works (fixed in docker/compose#8388).- How I did it
Added a
trimQuotes()helper inpkg/kvfile/kvfile.gothat strips the outermost matching quotes (single or double) from values. Only strips when first and last characters are the same quote type -- mismatched or missing quotes are left as-is.- How to verify it
Run the unit tests:
The new
TestTrimQuotescovers all the edge cases (matched/mismatched/nested/empty/single-char) andTestParseFromReaderQuotedValuesverifies end-to-end parsing with various quoting styles.You can also test manually:
Before this change,
FOOwould be"hello world"(with literal quotes). After, it'shello world.- Description for the changelog
docker run --env-filenow strips matching surrounding quotes from values, consistent with shellsourcebehavior anddocker compose.