-
-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: ignore empty form values in http request #4542
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files
|
5b2e3b6
to
e59038d
Compare
Changes Overview:
Detailed Review:
for name, values := range r.Form {
filtered := make([]string, 0, len(values))
for _, v := range values {
+ if len(v) == 0 {
+ continue
+ } ✅ This change is good because:
a. New test case for slice with comma-separated values: t.Run("slice with one value on array format", func(t *testing.T) {
var v struct {
Names string `form:"names"`
}
// ...
assert.Equal(t, "1,2,3", v.Names)
}) ✅ Good test coverage for comma-separated values b. Modified behavior for empty values: // Changed from asserting [""] to asserting empty
assert.Empty(t, v.Name)
// Changed from asserting ["", "1"] to asserting ["1"]
assert.ElementsMatch(t, []string{"1"}, v.Name) ✅ These changes are consistent with the new empty value filtering behavior c. New test cases for integer arrays: t.Run("slice with one value on integer array format", func(t *testing.T) {
var v struct {
Numbers []int `form:"numbers,optional"`
}
// ...
}) ✅ Good addition of tests for:
Suggestions for Improvement:
Security Considerations: Performance Impact: Compatibility: Overall Assessment: Recommendation: ✅ Approve |
e59038d
to
cb5e05e
Compare
823d819
to
5d2b734
Compare
Code Review Summary:
// ignore empty values, especially for optional int parameters
// e.g. /api?ids=
// e.g. /api
// type Req struct {
// IDs []int `form:"ids,optional"`
// }
if len(v) == 0 {
continue
} The added comments clearly explain the purpose and provide good examples of use cases. This is a beneficial improvement to the codebase.
Test improvements include: // Changed behavior:
- assert.ElementsMatch(t, []string{""}, v.Name)
+ assert.Empty(t, v.Name)
// And:
- assert.ElementsMatch(t, []string{"", "1"}, v.Name)
+ assert.ElementsMatch(t, []string{"1"}, v.Name) Strong Points:
Enhancement Suggestions:
Impact Analysis:
The PR looks ready to merge. The implementation is clean, well-tested, and properly documented. The behavior change is reasonable and improves the handling of form values, especially for optional numeric arrays. |
No description provided.