aboutsummaryrefslogtreecommitdiff
path: root/src/os/exec
diff options
context:
space:
mode:
Diffstat (limited to 'src/os/exec')
-rw-r--r--src/os/exec/exec.go10
-rw-r--r--src/os/exec/exec_test.go8
2 files changed, 7 insertions, 11 deletions
diff --git a/src/os/exec/exec.go b/src/os/exec/exec.go
index 0c49575511..9551c22d6e 100644
--- a/src/os/exec/exec.go
+++ b/src/os/exec/exec.go
@@ -748,12 +748,11 @@ func dedupEnvCase(caseInsensitive bool, env []string) []string {
out := make([]string, 0, len(env))
saw := make(map[string]int, len(env)) // key => index into out
for _, kv := range env {
- eq := strings.Index(kv, "=")
- if eq < 0 {
+ k, _, ok := strings.Cut(kv, "=")
+ if !ok {
out = append(out, kv)
continue
}
- k := kv[:eq]
if caseInsensitive {
k = strings.ToLower(k)
}
@@ -775,11 +774,10 @@ func addCriticalEnv(env []string) []string {
return env
}
for _, kv := range env {
- eq := strings.Index(kv, "=")
- if eq < 0 {
+ k, _, ok := strings.Cut(kv, "=")
+ if !ok {
continue
}
- k := kv[:eq]
if strings.EqualFold(k, "SYSTEMROOT") {
// We already have it.
return env
diff --git a/src/os/exec/exec_test.go b/src/os/exec/exec_test.go
index d854e0de84..459ba39dff 100644
--- a/src/os/exec/exec_test.go
+++ b/src/os/exec/exec_test.go
@@ -166,12 +166,10 @@ func TestCatGoodAndBadFile(t *testing.T) {
if _, ok := err.(*exec.ExitError); !ok {
t.Errorf("expected *exec.ExitError from cat combined; got %T: %v", err, err)
}
- s := string(bs)
- sp := strings.SplitN(s, "\n", 2)
- if len(sp) != 2 {
- t.Fatalf("expected two lines from cat; got %q", s)
+ errLine, body, ok := strings.Cut(string(bs), "\n")
+ if !ok {
+ t.Fatalf("expected two lines from cat; got %q", bs)
}
- errLine, body := sp[0], sp[1]
if !strings.HasPrefix(errLine, "Error: open /bogus/file.foo") {
t.Errorf("expected stderr to complain about file; got %q", errLine)
}