Skip to content

Fix CheckDisallowed for case-insensitive Windows env keys - #237

Open
ump45nose wants to merge 1 commit into
kelseyhightower:masterfrom
ump45nose:fix/236-checkdisallowed-windows-case
Open

ump45nose wants to merge 1 commit into
kelseyhightower:masterfrom
ump45nose:fix/236-checkdisallowed-windows-case

Conversation

@ump45nose

Copy link
Copy Markdown

Summary

CheckDisallowed uppercased the configured prefix and then used a case-sensitive strings.HasPrefix scan over os.Environ(). On Windows, Process finds variables through os.LookupEnv, which is case-insensitive, while os.Environ() keeps the original key spelling. That meant a lowercase app_unknown was missed by CheckDisallowed even though Process("app", …) would load app_known.

This change normalizes environ keys with the same Windows case folding before the prefix and allow-list checks, so CheckDisallowed matches Process on Windows. Unix behavior stays case-sensitive.

Fixes #236

Test plan

  • go test -count=1 ./... on Linux
  • TestEnvironKey asserts Windows uppercases / Unix preserves spelling
  • TestCheckDisallowedLowercasePrefixPreservedOnUnix keeps Unix case sensitivity
  • envconfig_windows_test.go (TestCheckDisallowedCaseInsensitive) covers the issue reproduction (unknown lowercase flagged; known lowercase allowed)

Assistance disclosed: this change was prepared with AI tooling; the patch and tests were reviewed before opening the PR.

Process uses LookupEnv, which matches environment variables
case-insensitively on Windows. CheckDisallowed scanned os.Environ()
with a case-sensitive prefix, so a lowercase app_unknown was ignored
while APP_UNKNOWN was reported.

Normalize environ keys with the same Windows case folding before the
prefix and allow-list checks. Keep Unix keys case-sensitive.

Fixes kelseyhightower#236
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.

CheckDisallowed misses lowercase-prefixed environment variables on Windows

1 participant