Skip to content

fix(conf): reject ambiguous keys and unset environment references - #5926

Open
kevwan wants to merge 1 commit into
masterfrom
fix/conf-ambiguous-keys-and-env-5852
Open

kevwan wants to merge 1 commit into
masterfrom
fix/conf-ambiguous-keys-and-env-5852

Conversation

@kevwan

@kevwan kevwan commented Dec 6, 2026

Copy link
Copy Markdown
Contributor

Part of #5852 (item 3).

Summary

  • Reject distinct keys that resolve to the same case-insensitive struct field, including fields inside slices and map values. Preserve the case of keys belonging to maps.
  • Apply the same expansion rules to Load and LoadProperties. With UseEnv(), an unset variable returns an error, an explicitly empty variable expands to an empty string, and $$ expands to one literal dollar.
  • Document these behavior changes and the existing env=NAME tag for field-level environment overrides.

Validation

  • go test -race ./core/conf ./core/mapping ./internal/encoding.

Copilot AI balanced review requested due to automatic review settings December 6, 2026 02:59
@codecov

codecov Bot commented Dec 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The change causes false collision errors for ignored embedded fields and incorrect parent-value selection for dotted JSON tags.

2 open issues
What changed in this PR

Hardens go-zero configuration loading by rejecting ambiguous struct-field keys and making environment expansion explicit and consistent.

Changes:

  • Reject case-colliding field keys while preserving map-key case.
  • Share environment expansion rules across Load and LoadProperties.
  • Add regression tests and document the updated behavior.
File Description
core/​conf/​readme.md Documents key matching and environment expansion.
core/​conf/​properties.go Uses shared expansion with contextual errors.
core/​conf/​properties_test.go Tests unset, empty, and escaped environment values.
core/​conf/​options.go Implements shared environment expansion rules.
core/​conf/​config.go Detects ambiguous keys and preserves nested map keys.
core/​conf/​config_test.go Tests key collisions and environment handling.

Review effort: Balanced

Comment thread core/conf/config.go
Comment on lines +332 to +333
if lower := toLowerCase(k); info.children[lower] != nil {
if previous, ok := seen[lower]; ok {
Comment thread core/conf/config.go
res[k] = toLowerCaseKeyMap(vv, info)
} else {
res[k] = v
if child != nil {
Copilot AI balanced review requested due to automatic review settings December 6, 2026 04:16
@kevwan
kevwan force-pushed the fix/conf-ambiguous-keys-and-env-5852 branch from 5d02d9d to f3933e1 Compare December 6, 2026 04:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Configuration loading now incorrectly rejects ignored-field keys and fails to traverse supported dotted JSON tags, breaking previously valid inputs.

2 open issues

Review effort: Balanced

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