dedupEnvCase is dedupEnv with a case option for testing. If caseInsensitive is true, the case of keys is ignored.
(caseInsensitive bool, env []string)
| 162 | // dedupEnvCase is dedupEnv with a case option for testing. |
| 163 | // If caseInsensitive is true, the case of keys is ignored. |
| 164 | func dedupEnvCase(caseInsensitive bool, env []string) []string { |
| 165 | out := make([]string, 0, len(env)) |
| 166 | saw := make(map[string]int, len(env)) // key => index into out |
| 167 | for _, kv := range env { |
| 168 | eq := strings.Index(kv, "=") |
| 169 | if eq < 0 { |
| 170 | out = append(out, kv) |
| 171 | continue |
| 172 | } |
| 173 | k := kv[:eq] |
| 174 | if caseInsensitive { |
| 175 | k = strings.ToLower(k) |
| 176 | } |
| 177 | if dupIdx, isDup := saw[k]; isDup { |
| 178 | out[dupIdx] = kv |
| 179 | continue |
| 180 | } |
| 181 | saw[k] = len(out) |
| 182 | out = append(out, kv) |
| 183 | } |
| 184 | return out |
| 185 | } |
| 186 | |
| 187 | // addCriticalEnv adds any critical environment variables that are required |
| 188 | // (or at least almost always required) on the operating system. |