From cba96c030119b2147075f4300b0ce76b873bac16 Mon Sep 17 00:00:00 2001 From: machupicchubeta Date: Thu, 20 Mar 2025 02:25:38 +0900 Subject: [PATCH] chore: Be tolerant to `ASDF_FORCE_PREPEND` environment variable I agree that it would be valid even if it is set in uppercase as well as lowercase. @Stratus3D commented: - https://github.com/asdf-vm/asdf/pull/2011#discussion_r1996208949 > We might want to be able to handle inconsistent case here. Some folks might set this to `YES` by mistake and I think that should be handled. --- internal/config/config.go | 2 +- internal/config/config_test.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/config/config.go b/internal/config/config.go index 7a074be5e..2395211e2 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -63,7 +63,7 @@ type Settings struct { func defaultConfig(dataDir, configFile string) *Config { forcePrepend := forcePrependDefault forcePrependEnv := os.Getenv("ASDF_FORCE_PREPEND") - if forcePrependEnv == "yes" || (forcePrependEnv == "" && runtime.GOOS == "darwin") { + if strings.ToLower(forcePrependEnv) == "yes" || (forcePrependEnv == "" && runtime.GOOS == "darwin") { forcePrepend = true } return &Config{ diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 56d55ae7f..cb4db5062 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -33,6 +33,14 @@ func TestLoadConfigEnv_WithForcePrependEnv(t *testing.T) { assert.True(t, config.ForcePrepend, "Then ForcePrepend property is true") }) + t.Run("When ASDF_FORCE_PREPEND env given YES", func(t *testing.T) { + t.Setenv("ASDF_FORCE_PREPEND", "YES") + + config, _ := loadConfigEnv() + + assert.True(t, config.ForcePrepend, "Then ForcePrepend property is true") + }) + t.Run("When ASDF_FORCE_PREPEND env given any string other than yes", func(t *testing.T) { t.Setenv("ASDF_FORCE_PREPEND", "no")