Repository: gohugoio/hugo (language: go)

Issue:
Env HUGO_DISABLELANGUAGES is not working after v0.111.3 with multiple values
<!-- Please answer these questions before submitting your issue. Thanks! -->

### What version of Hugo are you using (`hugo version`)?

<pre>
$ hugo version
hugo v0.112.0+extended freebsd/amd64 BuildDate=2023-07-20T22:16:20Z-0300 VendorInfo=freebsd

and

$ hugo version
hugo v0.115.4+extended freebsd/amd64 BuildDate=2023-07-20T22:31:17Z-0300 VendorInfo=freebsd
</pre>

### Does this issue reproduce with the latest release?
yes

---

Behavior with v0.111.3:
```
$ hugo version
hugo v0.111.3+extended freebsd/amd64 BuildDate=2023-03-17T03:01:46Z+0000 VendorInfo=freebsd

$ HUGO_DISABLELANGUAGES=" bn-bd da de el es fr hu id it ja ko mn nl pl ru tr zh-cn zh-tw" hugo config | grep -i disablelanguage
disablelanguages: "bn-bd da de el es fr hu id it ja ko mn nl pl ru tr zh-cn zh-tw"

$  HUGO_DISABLELANGUAGES="fr es" hugo config | grep -i disablelanguage
disablelanguages: "fr es"
```

And now with v0.112.0 and v0.115.4:

```
$  hugo version
hugo v0.112.0+extended freebsd/amd64 BuildDate=2023-07-20T22:16:20Z-0300 VendorInfo=freebsd

$ HUGO_DISABLELANGUAGES=" bn-bd da de el es fr hu id it ja ko mn nl pl ru tr zh-cn zh-tw" hugo config | grep -i disablelanguage
disablelanguages = ['bn-bd da de el es fr hu id it ja ko mn nl pl ru tr zh-cn zh-tw']

$ HUGO_DISABLELANGUAGES="fr es" /usr/local/bin/hugo config | grep -i disablelanguage
disablelanguages = ['fr es']
```

```
$ hugo version
hugo v0.115.4+extended freebsd/amd64 BuildDate=2023-07-20T22:31:17Z-0300 VendorInfo=freebsd

$ HUGO_DISABLELANGUAGES=" bn-bd da de el es fr hu id it ja ko mn nl pl ru tr zh-cn zh-tw" hugo config | grep -i disablelanguage
disablelanguages = ['bn-bd da de el es fr hu id it ja ko mn nl pl ru tr zh-cn zh-tw']

$ HUGO_DISABLELANGUAGES="fr es" /usr/local/bin/hugo config | grep -i disablelanguage
disablelanguages = ['fr es']
```

The intended behavior should be `disableLanguages = ['fr', 'es']`, right?
This other way, hugo is building all languages every time.



Discussion / hints:
With v0.112.0 and later...

#### PASS - Disable multiple languages in site configuration via language object

```toml
[languages.en]
weight = 1

[languages.de]
disabled = true
weight = 2

[languages.fr]
disabled = true
weight = 3
```

#### PASS - Disable multiple languages in site configuration via root setting

```toml
disableLanguages = ['de', 'fr']
```

#### PASS - Disable a single language via environment variable

```text
HUGO_DISABLELANGUAGES="de" hugo
```

#### FAIL - Disable multiple languages via environment variable

```text
HUGO_DISABLELANGUAGES="de fr" hugo
```

---

We have the same failure with...

```text
HUGO_DISABLEKINDS="RSS taxonomy term sitemap" hugo
```

The above worked prior to v0.112.0.


> With v0.112.0 and later...
> 
> This works (disables a single language):
> 
> ```
> HUGO_DISABLELANGUAGES="de" hugo
> ```
> 
> This does not (does not disable any language):
> 
> ```
> HUGO_DISABLELANGUAGES="de fr" hugo
> ```


I've changed the PR title to 'is not working with multiple values'. Thanks.


Fix patch:
diff --git a/config/allconfig/load.go b/config/allconfig/load.go
index 8551039a0ee..91cf1eb056b 100644
--- a/config/allconfig/load.go
+++ b/config/allconfig/load.go
@@ -297,14 +297,20 @@ func (l configLoader) applyOsEnvOverrides(environ []string) error {
 			if nestedKey != "" {
 				owner[nestedKey] = env.Value
 			} else {
-				var val any = env.Value
-				if _, ok := allDecoderSetups[env.Key]; ok {
+				var val any
+				key := strings.ReplaceAll(env.Key, delim, ".")
+				_, ok := allDecoderSetups[key]
+				if ok {
 					// A map.
-					val, err = metadecoders.Default.UnmarshalStringTo(env.Value, map[string]interface{}{})
+					if v, err := metadecoders.Default.UnmarshalStringTo(env.Value, map[string]interface{}{}); err == nil {
+						val = v
+					}
 				}
-				if err == nil {
-					l.cfg.Set(strings.ReplaceAll(env.Key, delim, "."), val)
+				if val == nil {
+					// A string.
+					val = l.envStringToVal(key, env.Value)
 				}
+				l.cfg.Set(key, val)
 			}
 		}
 	}
@@ -312,6 +318,20 @@ func (l configLoader) applyOsEnvOverrides(environ []string) error {
 	return nil
 }
 
+func (l *configLoader) envStringToVal(k, v string) any {
+	switch k {
+	case "disablekinds", "disablelanguages":
+		if strings.Contains(v, ",") {
+			return strings.Split(v, ",")
+		} else {
+			return strings.Fields(v)
+		}
+	default:
+		return v
+	}
+
+}
+
 func (l *configLoader) loadConfigMain(d ConfigSourceDescriptor) (config.LoadConfigResult, modules.ModulesConfig, error) {
 	var res config.LoadConfigResult
 


Test patch:
diff --git a/hugolib/config_test.go b/hugolib/config_test.go
index ff7b01a3fa7..a39d5778197 100644
--- a/hugolib/config_test.go
+++ b/hugolib/config_test.go
@@ -259,6 +259,47 @@ sub: map[sub1:sub1en]
 
 }
 
+func TestDisableRootSlicesFromEnv(t *testing.T) {
+	t.Parallel()
+
+	files := `
+-- hugo.toml --
+baseURL = "https://example.com"
+defaultContentLanguage = "en"
+defaultContentLanguageInSubdir = true
+[languages]
+[languages.en]
+weight = 1
+[languages.sv]
+weight = 2
+[languages.no]
+weight = 3
+
+-- layouts/index.html --
+Home.
+`
+
+	for _, delim := range []string{" ", ","} {
+		environ := []string{"HUGO_DISABLELANGUAGES=sv no", "HUGO_DISABLEKINDS=taxonomy term"}
+		for i, v := range environ {
+			environ[i] = strings.ReplaceAll(v, " ", delim)
+		}
+		b := NewIntegrationTestBuilder(
+			IntegrationTestConfig{
+				T:           t,
+				TxtarString: files,
+				Environ:     environ,
+				BuildCfg:    BuildCfg{SkipRender: true},
+			},
+		).Build()
+
+		conf := b.H.Configs.Base
+		b.Assert(conf.DisableLanguages, qt.DeepEquals, []string{"sv", "no"})
+		b.Assert(conf.DisableKinds, qt.DeepEquals, []string{"taxonomy", "term"})
+	}
+
+}
+
 func TestLoadMultiConfig(t *testing.T) {
 	t.Parallel()