-
Notifications
You must be signed in to change notification settings - Fork 2.1k
stack/loader: Ignore cmd.exe special env variables #4081
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import ( | |
| "io" | ||
| "os" | ||
| "path/filepath" | ||
| "runtime" | ||
| "sort" | ||
| "strings" | ||
|
|
||
|
|
@@ -104,9 +105,22 @@ func GetConfigDetails(composefiles []string, stdin io.Reader) (composetypes.Conf | |
| func buildEnvironment(env []string) (map[string]string, error) { | ||
| result := make(map[string]string, len(env)) | ||
| for _, s := range env { | ||
| if runtime.GOOS == "windows" && len(s) > 0 { | ||
| // cmd.exe can have special environment variables which names start with "=". | ||
| // They are only there for MS-DOS compatibility and we should ignore them. | ||
| // See TestBuildEnvironment for examples. | ||
| // | ||
| // https://ss64.com/nt/syntax-variables.html | ||
| // https://devblogs.microsoft.com/oldnewthing/20100506-00/?p=14133 | ||
| // https://github.com/docker/cli/issues/4078 | ||
| if s[0] == '=' { | ||
| continue | ||
| } | ||
| } | ||
|
|
||
| k, v, ok := strings.Cut(s, "=") | ||
| if !ok || k == "" { | ||
|
Comment on lines
121
to
122
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was wondering if the case above could also be checked as; if ok && k == "" && runtime.GOOS == "windows" {
// windows handling hereBut not sure if that would make it actually more readable than your implementation, and won't give us a performance benefice, so .. bad suggestion I guess 😂
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the version as written is better as it makes the intention more obvious. |
||
| return result, errors.Errorf("unexpected environment %q", s) | ||
| return result, errors.Errorf("unexpected environment variable '%s'", s) | ||
| } | ||
| // value may be set, but empty if "s" is like "K=", not "K". | ||
| result[k] = v | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't make this one an explicit blacklist of variables, because:
so user can't deliberately set such variable nor anyone other than
cmd.exeshould actually set such variables.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, thanks!
So;
os.Environ()should take into account (if that would make sense) and possibly filter out those "env-vars" (might be worth opening a ticket for in Golang, and see if there's opinions on that)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There look to be existing Golang issues related to this: