From d00f447739c15e1081ecbac999ab74d38849671b Mon Sep 17 00:00:00 2001 From: Aaron Liu Date: Wed, 15 Jul 2026 15:50:26 +0800 Subject: [PATCH] fix(conf): enhance environment variable parsing for configuration overrides (close #3498) --- pkg/conf/conf.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pkg/conf/conf.go b/pkg/conf/conf.go index 3f5bbd3b..1b703aac 100644 --- a/pkg/conf/conf.go +++ b/pkg/conf/conf.go @@ -166,9 +166,26 @@ func getOverrideConfFromEnv(l logging.Logger) string { // split by key=value and get key kv := strings.SplitN(env, "=", 2) + if len(kv) < 2 { + continue + } configKey := strings.TrimPrefix(kv[0], envConfOverrideKey) configValue := kv[1] + + // Prefer the native "." separator. Fall back to "__" so that TOML-based + // deployment platforms (Fly.io, some Docker Compose variants) that + // mangle dotted env var names can still express Section/Key overrides + // as CR_CONF_Section__Key. sectionKey := strings.SplitN(configKey, ".", 2) + if len(sectionKey) < 2 { + sectionKey = strings.SplitN(configKey, "__", 2) + } + if len(sectionKey) < 2 || sectionKey[0] == "" || sectionKey[1] == "" { + l.Warning("Skipping malformed %s override %q: expected %sSection.Key or %sSection__Key format", + envConfOverrideKey, kv[0], envConfOverrideKey, envConfOverrideKey) + continue + } + if confMaps[sectionKey[0]] == nil { confMaps[sectionKey[0]] = make(map[string]string) }