Skip to content

Commit

Permalink
refactor: simplify toMap on Windows implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear committed Nov 20, 2024
1 parent a9fcfa3 commit 6d9c7a5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
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 @@ import "strings"
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

0 comments on commit 6d9c7a5

Please sign in to comment.