From 8b2b4b8675992e4ca53ca0bd50ecdc4182614bac Mon Sep 17 00:00:00 2001 From: Joe Buck Date: Thu, 18 Feb 2016 21:48:15 -0800 Subject: [PATCH] Replace "." characters with "_" when parsing environment variables This brings viper in line with other configuration parsing libraries and in line with what I would anticipate are the expectations of most programms. --- viper.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/viper.go b/viper.go index 7a49a0a..0f0a6d4 100644 --- a/viper.go +++ b/viper.go @@ -305,6 +305,10 @@ func (v *Viper) getEnv(key string) string { if v.envKeyReplacer != nil { key = v.envKeyReplacer.Replace(key) } + + // Replace dots with underscores, since that is the sensible mapping + // for environment variables. The -1 means replace all insstances of "." with "_" + key = strings.Replace(key, ".", "_", -1) return os.Getenv(key) }