fix(gconv): prevent panic when binding array type (uuid.UUID) parameters (#4786) - #4820
Open
waterWang wants to merge 1 commit into
Open
fix(gconv): prevent panic when binding array type (uuid.UUID) parameters (#4786)#4820waterWang wants to merge 1 commit into
waterWang wants to merge 1 commit into
Conversation
reflect.Value.IsNil panics when called on an array value. uuid.UUID is [16]byte (a fixed-size array), so when a struct field like is bound via HTTP request, the converter enters the reflect.Slice/Array/Pointer/Interface case and calls IsNil on the array element, causing a panic. Fix: skip the IsNil check when the kind is reflect.Array, since arrays can never be nil in Go. Fixes gogf#4786
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 #4786
Problem
reflect.Value.IsNilpanics when called on an array value.uuid.UUIDis[16]byte(a fixed-size array), so when a struct field like:is bound via HTTP request, the converter enters the
reflect.Slice/Array/Pointer/Interfacecase and callsIsNilon the array element, causing a panic:Fix
Skip the
IsNilcheck when thereflect.Kindisreflect.Array, since arrays can never be nil in Go.Verification
reflect.Arrayvalues are never nil, so theIsNil()guard is unnecessary for arraysISetinterface check is still reached for array types that implement it (though no standard library array type does)