Skip to content
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

refactor: simplify toMap on Windows implementation #343

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ linters:
- unparam
- wastedassign
- revive
- ineffassign
12 changes: 3 additions & 9 deletions env_tomap_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,10 @@
func toMap(env []string) map[string]string {
r := map[string]string{}
for _, e := range env {
p := strings.SplitN(e, "=", 2)

// On Windows, environment variables can start with '='. If so, Split at next character.
// See env_windows.go in the Go source: https://github.com/golang/go/blob/master/src/syscall/env_windows.go#L58
prefixEqualSign := false
if len(e) > 0 && e[0] == '=' {
e = e[1:]
prefixEqualSign = true
}
p = strings.SplitN(e, "=", 2)
// See env_windows.go in the Go source: https://github.com/golang/go/blob/go1.18/src/syscall/env_windows.go#L58
e, prefixEqualSign := strings.CutPrefix(e, "=")

Check failure on line 12 in env_tomap_windows.go

View workflow job for this annotation

GitHub Actions / build (windows-latest, 1.18)

undefined: strings.CutPrefix
p := strings.SplitN(e, "=", 2)
if prefixEqualSign {
p[0] = "=" + p[0]
}
Expand Down
Loading