From bcf0a0f0036c8e6c7b955879c4a5eeb59e3f7be9 Mon Sep 17 00:00:00 2001 From: crawfordxx Date: Thu, 18 Jun 2026 12:11:20 +0800 Subject: [PATCH] generate: key envMap by variable name rather than full env string createEnvCacheMap was storing the full 'KEY=value' string as the map key. addEnv looks entries up by just the variable name ('KEY'), so every lookup missed and AddProcessEnv/RemoveProcessEnv always appended a new entry instead of replacing the existing one. Fix by extracting the name part (everything before the first '=') and using that as the map key, consistent with how addEnv performs lookups. Signed-off-by: crawfordxx --- generate/generate.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/generate/generate.go b/generate/generate.go index 816305f0..88782477 100644 --- a/generate/generate.go +++ b/generate/generate.go @@ -318,11 +318,14 @@ func NewFromTemplate(r io.Reader) (Generator, error) { }, nil } -// createEnvCacheMap creates a hash map with the ENV variables given by the config +// createEnvCacheMap creates a hash map with the ENV variables given by the config. +// The map is keyed by the variable name (the part before the first '=') so that +// addEnv can look up existing entries by name and replace them in-place. func createEnvCacheMap(env []string) map[string]int { envMap := make(map[string]int, len(env)) for i, val := range env { - envMap[val] = i + name, _, _ := strings.Cut(val, "=") + envMap[name] = i } return envMap }