Skip to content

Avoid panics when decode hooks receive named strings - #201

Open
a3ylf wants to merge 1 commit into
go-viper:mainfrom
a3ylf:fix/named-string-decode-hooks
Open

a3ylf wants to merge 1 commit into
go-viper:mainfrom
a3ylf:fix/named-string-decode-hooks

Conversation

@a3ylf

@a3ylf a3ylf commented Sep 16, 2026 •

Copy link
Copy Markdown

Built-in string decode hooks accept any source whose reflected kind is string, but asserting data.(string) panics for defined types such as type ConfigValue string. Read the reflected string value after the existing kind checks so these inputs follow the same parsers and error paths as ordinary strings.

Tests exercise named and ordinary strings across the built-in conversions, plus full decoding into named-string slices and IP networks. go test -race -shuffle=on ./... passes. The changed code passes lint; the full lint run with v2.13.2 reports three existing govet findings in unchanged mapstructure.go.

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.

1 participant