Skip to content

fix: nil map assignment panics on zero-value Viper struct#2124

Open
humanborch wants to merge 1 commit intospf13:masterfrom
humanborch:fix-nil-map-struct
Open

fix: nil map assignment panics on zero-value Viper struct#2124
humanborch wants to merge 1 commit intospf13:masterfrom
humanborch:fix-nil-map-struct

Conversation

@humanborch
Copy link
Copy Markdown

Overview:
Lazily initializes internally mutated maps and key delimiters inside viper.Set and viper.SetDefault methods, enabling safe, immediate usability of an uninitialized zero-value &viper.Viper{} struct without map assignment panics.

What problem does it solve?:

  • Fixes a core configuration bug where invoking overriding functions on explicitly constructed zero-value Viper instances (v := &viper.Viper{}) immediately crashes the host application deep inside util.go.
  • Pre-handling v.keyDelim initialization prevents unintended character-by-character map splitting on empty delimiter bindings.
  • Closes Zero-value Viper struct panics on SetDefault/Set (nil map assignment) #2111

Special notes for a reviewer:
Added test-cases (TestZeroValueViperSetDefault, TestZeroValueViperSet) into the test suite that specifically execute map-binding assignments on the zero-value struct pattern to protect against regression.

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.

Zero-value Viper struct panics on SetDefault/Set (nil map assignment)

1 participant