Skip to content

Environment variable parsing for list config differs if list exists #13950

@ZhenShuo2021

Description

@ZhenShuo2021

What version of Hugo are you using (hugo version)?

$ hugo version
hugo v0.149.0-66240338f1b908ca3b163384c8229943e74eb290+extended darwin/arm64 BuildDate=2025-08-27T15:37:16Z VendorInfo=gohugoio

Does this issue reproduce with the latest release?

Yes

Describe the bug

When setting a Hugo configuration value of type list via an environment variable, the parsing result depends on whether the config file already defines the key as a list. If the key does not exist or is undefined, the environment variable is interpreted as a single string. If the key exists as a list, the environment variable is correctly parsed as a list.

Reproduce

  1. Clone a test repository (arbitrary example):
git clone https://github.com/jmooring/hugo-testing --single-branch --branch=hugo-forum-topic-55568
cd hugo-testing
  1. Without defining ignoreFiles in the config:

HUGO_IGNOREFILES='[foo,bar]' hugo config | grep ignore
HUGO_IGNOREFILES='["foo","bar"]' hugo config | grep ignore

Result:

ignorefiles = ['[foo,bar]']
  1. Create an empty list in the config:
(echo 'ignoreFiles = []'; cat hugo.toml) > tmp && mv tmp hugo.toml
  1. Run the same command again:

HUGO_IGNOREFILES='[foo,bar]' hugo config | grep ignore
HUGO_IGNOREFILES='["foo","bar"]' hugo config | grep ignore

Result:

ignorefiles = ['foo', 'bar']

Expected behavior

Environment variables defining list-type config keys should be parsed consistently regardless of whether the key exists in the config file.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions