Resolve environments case-insensitively on Windows#257
Resolve environments case-insensitively on Windows#257glours merged 2 commits intocompose-spec:masterfrom
Conversation
|
Thanks for looking into this! |
types/config.go
Outdated
| // LookupEnv provides a lookup function for environment variables | ||
| func (cd ConfigDetails) LookupEnv(key string) (string, bool) { | ||
| v, ok := cd.Environment[key] | ||
| v, ok := utils.EnvResolver(cd.Environment)(key) |
There was a problem hiding this comment.
as EnvResolver is not used in any other place, I'd prefer we keep things simple with EnvResolverWithCase logic being directly included here
utils/envresolver.go
Outdated
| if ok { | ||
| return v, ok | ||
| } | ||
| if loweredEnvironment == nil { |
There was a problem hiding this comment.
No need to allocate a full lowercase map on each lookup, could just do
key := strings.ToLower(s)
for k, v := range environment {
if key == strings.ToLower(k) {
return v
}
}
utils/envresolver_test.go
Outdated
| "gotest.tools/v3/assert" | ||
| ) | ||
|
|
||
| func Test_EnvResolverWithCase(t *testing.T) { |
I've added signed-off line as described in https://github.com/compose-spec/compose-go/blob/master/CONTRIBUTING.md : But something might be wrong as this is the first time I wrote signed-off line. Should I use the real name also in author line? Or should I add GPG signature? (git commit -S) |
2f6d078 to
85892a2
Compare
|
Oh, I got it. I have to pass DCO action. I'll try that. |
85892a2 to
4fcc599
Compare
|
Thanks for the review. I fixed problems you pointed. |
Signed-off-by: IKEDA Yasuyuki <devld@ikedam.jp>
Signed-off-by: IKEDA Yasuyuki <devld@ikedam.jp>
4fcc599 to
eeab8f0
Compare
Please have a look on docker/compose#9431 for details.
compose-go extracts environment variables to
Environment map[string]stringand reference that later with simplyEnvironment[varname].It works case-sensitively but environment variables should be treated case-insensitively on Windows.
This change handles environment variables case-insensitively on Windows, without changing data structures on compose-go.
This change also adds exposed
utils.EnvResolverfunction. I plan to use that for additional changes in https://github.com/docker/compose/ , handling option args like--build-argwithbuildsub command and-ewithrunsub command.(like this: https://github.com/ikedam/compose/pull/1/files)