8000 Add env file quotes handling by photra · Pull Request #3660 · docker/cli · GitHub
[go: up one dir, main page]

Skip to content

Add env file quotes handling#3660

Open
photra wants to merge 3 commits intodocker:masterfrom
photra:3630-add-env-quotes-handling
Open

Add env file quotes handling#3660
photra wants to merge 3 commits intodocker:masterfrom
photra:3630-add-env-quotes-handling

Conversation

@photra
Copy link
Contributor
@photra photra commented Jun 6, 2022

- What I did
Closes #3630

- How I did it
Added quotes trimming for env files

- How to verify it
Run the updated unit test TestParseEnvFileGoodFile

- Description for the changelog
Added --env-file quotes handling

- A picture of a cute animal (not mandatory but encouraged)

Signed-off-by: Phong Tran <tran.pho@northeastern.edu>
@codecov-commenter
Copy link
codecov-commenter commented Jun 6, 2022

Codecov Report

Merging #3660 (3efdec6) into master (b75c262) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head 3efdec6 differs from pull request most recent head 383769a. Consider uploading reports for the commit 383769a to get more accurate results

@@           Coverage Diff           @@
##           master    #3660   +/-   ##
=======================================
  Coverage   59.02%   59.02%           
=======================================
  Files         289      289           
  Lines       24626    24630    +4     
=======================================
+ Hits        14535    14539    +4     
  Misses       9218     9218           
  Partials      873      873           

opts/file.go Outdated
Comment on lines +65 to +67
value := data[1]
value = strings.TrimLeft(value, quotes)
value = strings.TrimRight(value, quotes)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably make sure that we only trim the "outer" quotes, and only if "left" and "right" have the same quote; I was writing along some ideas for that, and push it as a PR against your branch photra#2

Overall, we should look if there's potential side-effects / changes in behavior because of this though 😅 - perhaps there's other expectations (such as, when using single quotes, don't expand other env-vars inside the value).

I know the original design for the env-file was explicitly to only split on =, and nothing else.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that parseKeyValueFile() is also used in other parts of the code, we may need to check if we want the behavior to change for those areas as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point! I checked parseKeyValueFile() and after evaluating readKVStrings() and ParseEnvFile(), syntactically there shouldn't be side effects given their signatures.

Additionally, I read our documentation on --env-file, and it looks like we do not perform any operations on the variable or its value. Where we do this is within the Dockerfile when using shell form:

"When using the exec form and executing a shell directly, as in the case for the shell form, it is the shell that is doing the environment variable expansion, not docker."

I think we should be OK on env-file behavior, but we should look closer for Dockerfile image building. I'll update here if I find anything. Let me know if you found something!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 Hi guys

Any update on this? If not, I can look into a solution

thaJeztah and others added 2 commits June 9, 2022 08:08
This makes sure that only the outer-most quotes are trimmed, and
that quotes are only trimmed if equal (start/end).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
…gestions

use trimQuotes() for trimming quotes
@phrfpeixoto
Copy link

This is sitting here for 2 years now?

@ysmood
Copy link
ysmood commented Dec 25, 2024

Any progress?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle quotes in --env-file values consistently with Linux/WSL2 "source"ing

6 participants

0