Fix panic on missing or non-map query parameter object#278
Open
SebTardif wants to merge 1 commit into
Open
Conversation
Replace bare type assertion with comma-ok pattern to prevent panic when query parameter object key is absent or value is not a map.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #278 +/- ##
==========================================
- Coverage 97.63% 97.58% -0.06%
==========================================
Files 64 64
Lines 6991 6999 +8
==========================================
+ Hits 6826 6830 +4
- Misses 132 134 +2
- Partials 33 35 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Problem
In
parameters/query_parameters.go, thehelpers.Objectcase uses a bare type assertion:This panics when:
encodedObjis nil (e.g. content-wrapped parameter with a non-JSON media type skips map initialization)params[p].Nameis absent fromencodedObj(map lookup returns nil, bare assertion on nil panics)map[string]interface{}Fix
Replace the bare type assertion with a three-step comma-ok pattern:
This follows the existing control flow: when the value cannot be decoded, we
break skipValues(the same pattern used for JSON unmarshal failures a few lines above).Test
Added
TestQueryParamObjectMissingKey_NoPanicwhich declares an object query parameter with atext/plaincontent wrapper. This forces thecontentWrappedpath without JSON decoding, leavingencodedObjnil. Before the fix, this test panics. After the fix, it completes without error.