Skip to content

fix: expand environment variables in string slices - #230

Merged
inhere merged 1 commit into
gookit:masterfrom
tridev-tej:tejesh/fix-strings-env-expansion
Oct 26, 2026
Merged

inhere merged 1 commit into
gookit:masterfrom
tridev-tej:tejesh/fix-strings-env-expansion

Conversation

@tridev-tej

Copy link
Copy Markdown
Contributor

Strings skipped environment expansion for slice elements

I apply ParseEnv to string elements in both supported slice types, preserve raw data, and keep existing conversion and cache behavior

@inhere
inhere merged commit e7757e6 into gookit:master Oct 26, 2026
12 checks passed
inhere added a commit that referenced this pull request Oct 26, 2026
…t the contract

Follow up of #230:

- rename Config.stringValue() to parseEnvString(), and document what it does
- document the Strings() contract: with ParseEnv the string elems are parsed and a
  copy is returned, otherwise the []string value of the config data may be returned
  as is
- note in TestStringsParseEnvCache that a cache hit keeps the value expanded on the
  first read (the same as the String() cache), it is not a missed invalidation
- drop a dead comment line in the []any branch
inhere added a commit that referenced this pull request Oct 27, 2026
Ints and IntMap handed the raw elem/value to mathutil.ToInt, so with ParseEnv a
"${PORT}" elem failed with "cannot convert to int", while the scalar Int, Uint,
Float and Bool read the env value through getString. Strings (#230) and StringMap
(#232) already parse env for their string elem/value, so this was the last of the
group.

- parse a string elem/value with ParseEnvValue before the conversion, through the
  new parseEnvValue helper; parseEnvString is a thin wrapper of it now.
- Ints accepts a []string value from Set, and IntMap a map[string]string one, which
  returned the "value cannot be convert" error before.
- with ParseEnv off nothing is parsed, the conversions are the same as before.

Tests: the four value shapes ([]any, []string, map[string]any, map[string]string)
with ParseEnv on, plus the no-env branch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants