fix: support pointer slices in nonunique section mapping#381
Open
Yanhu007 wants to merge 1 commit intogo-ini:mainfrom
Open
fix: support pointer slices in nonunique section mapping#381Yanhu007 wants to merge 1 commit intogo-ini:mainfrom
Yanhu007 wants to merge 1 commit intogo-ini:mainfrom
Conversation
When a struct field is a slice of struct pointers (e.g. []*Peer), mapToSlice used reflect.New on the pointer type, creating a **Peer. mapToField only dereferences one level, causing a panic. Detect when the slice element type is a pointer, allocate the underlying struct type, and append the pointer to the slice. Fixes go-ini#370
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #370
Problem
When mapping INI sections to a struct with a slice of struct pointers:
mapToSlicecallsreflect.New(typ)wheretypis*Peer, creating a**Peer. ThenmapToFieldonly dereferences one level of pointer, causing a panic.Fix
Detect when the slice element type is a pointer:
Peer) instead of the pointer type*Peer) to the slice instead of the struct valueTesting
All existing tests pass. Manually verified with the reproduction case from the issue: