-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
🐛 bug: fix EnableSplittingOnParsers is not functional #3231
Changes from 8 commits
725855d
2260663
a56943d
8ce1fb4
043dd20
d2d2ab7
6dea77f
e2e93a4
47a8f32
e89943b
182d53a
7d50265
2ac8bbf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,7 +77,15 @@ | |
|
||
// Header binds the request header strings into the struct, map[string]string and map[string][]string. | ||
func (b *Bind) Header(out any) error { | ||
if err := b.returnErr(binder.HeaderBinder.Bind(b.ctx.Request(), out)); err != nil { | ||
bind := binder.GetFromThePool[*binder.HeaderBinding](&binder.HeaderBinderPool) | ||
bind.EnableSplitting = b.ctx.App().config.EnableSplittingOnParsers | ||
|
||
// Reset & put binder | ||
defer func() { | ||
bind.Reset() | ||
}() | ||
|
||
if err := b.returnErr(bind.Bind(b.ctx.Request(), out)); err != nil { | ||
return err | ||
} | ||
|
||
|
@@ -86,7 +94,15 @@ | |
|
||
// RespHeader binds the response header strings into the struct, map[string]string and map[string][]string. | ||
func (b *Bind) RespHeader(out any) error { | ||
if err := b.returnErr(binder.RespHeaderBinder.Bind(b.ctx.Response(), out)); err != nil { | ||
bind := binder.GetFromThePool[*binder.RespHeaderBinding](&binder.RespHeaderBinderPool) | ||
bind.EnableSplitting = b.ctx.App().config.EnableSplittingOnParsers | ||
|
||
// Reset & put binder | ||
defer func() { | ||
bind.Reset() | ||
}() | ||
|
||
if err := b.returnErr(bind.Bind(b.ctx.Response(), out)); err != nil { | ||
return err | ||
} | ||
|
||
|
@@ -96,7 +112,15 @@ | |
// Cookie binds the request cookie strings into the struct, map[string]string and map[string][]string. | ||
// NOTE: If your cookie is like key=val1,val2; they'll be binded as an slice if your map is map[string][]string. Else, it'll use last element of cookie. | ||
func (b *Bind) Cookie(out any) error { | ||
if err := b.returnErr(binder.CookieBinder.Bind(b.ctx.RequestCtx(), out)); err != nil { | ||
bind := binder.GetFromThePool[*binder.CookieBinding](&binder.CookieBinderPool) | ||
bind.EnableSplitting = b.ctx.App().config.EnableSplittingOnParsers | ||
|
||
// Reset & put binder | ||
defer func() { | ||
bind.Reset() | ||
}() | ||
|
||
if err := b.returnErr(bind.Bind(&b.ctx.RequestCtx().Request, out)); err != nil { | ||
return err | ||
} | ||
|
||
|
@@ -105,7 +129,15 @@ | |
|
||
// Query binds the query string into the struct, map[string]string and map[string][]string. | ||
func (b *Bind) Query(out any) error { | ||
if err := b.returnErr(binder.QueryBinder.Bind(b.ctx.RequestCtx(), out)); err != nil { | ||
bind := binder.GetFromThePool[*binder.QueryBinding](&binder.QueryBinderPool) | ||
bind.EnableSplitting = b.ctx.App().config.EnableSplittingOnParsers | ||
|
||
// Reset & put binder | ||
defer func() { | ||
bind.Reset() | ||
}() | ||
|
||
if err := b.returnErr(bind.Bind(&b.ctx.RequestCtx().Request, out)); err != nil { | ||
return err | ||
} | ||
|
||
|
@@ -114,7 +146,15 @@ | |
|
||
// JSON binds the body string into the struct. | ||
func (b *Bind) JSON(out any) error { | ||
if err := b.returnErr(binder.JSONBinder.Bind(b.ctx.Body(), b.ctx.App().Config().JSONDecoder, out)); err != nil { | ||
bind := binder.GetFromThePool[*binder.JSONBinding](&binder.JSONBinderPool) | ||
bind.JSONDecoder = b.ctx.App().Config().JSONDecoder | ||
|
||
// Reset & put binder | ||
defer func() { | ||
bind.Reset() | ||
}() | ||
|
||
if err := b.returnErr(bind.Bind(b.ctx.Body(), out)); err != nil { | ||
return err | ||
} | ||
|
||
|
@@ -123,15 +163,31 @@ | |
|
||
// CBOR binds the body string into the struct. | ||
func (b *Bind) CBOR(out any) error { | ||
if err := b.returnErr(binder.CBORBinder.Bind(b.ctx.Body(), b.ctx.App().Config().CBORDecoder, out)); err != nil { | ||
bind := binder.GetFromThePool[*binder.CBORBinding](&binder.CBORBinderPool) | ||
bind.CBORDecoder = b.ctx.App().Config().CBORDecoder | ||
|
||
// Reset & put binder | ||
defer func() { | ||
bind.Reset() | ||
}() | ||
|
||
if err := b.returnErr(bind.Bind(b.ctx.Body(), out)); err != nil { | ||
return err | ||
} | ||
return b.validateStruct(out) | ||
} | ||
|
||
// XML binds the body string into the struct. | ||
func (b *Bind) XML(out any) error { | ||
if err := b.returnErr(binder.XMLBinder.Bind(b.ctx.Body(), out)); err != nil { | ||
bind := binder.GetFromThePool[*binder.XMLBinding](&binder.XMLBinderPool) | ||
bind.XMLDecoder = b.ctx.App().config.XMLDecoder | ||
|
||
// Reset & put binder | ||
defer func() { | ||
bind.Reset() | ||
}() | ||
|
||
if err := b.returnErr(bind.Bind(b.ctx.Body(), out)); err != nil { | ||
return err | ||
} | ||
|
||
|
@@ -140,7 +196,15 @@ | |
|
||
// Form binds the form into the struct, map[string]string and map[string][]string. | ||
func (b *Bind) Form(out any) error { | ||
if err := b.returnErr(binder.FormBinder.Bind(b.ctx.RequestCtx(), out)); err != nil { | ||
bind := binder.GetFromThePool[*binder.FormBinding](&binder.FormBinderPool) | ||
bind.EnableSplitting = b.ctx.App().config.EnableSplittingOnParsers | ||
|
||
// Reset & put binder | ||
defer func() { | ||
bind.Reset() | ||
}() | ||
|
||
if err := b.returnErr(bind.Bind(&b.ctx.RequestCtx().Request, out)); err != nil { | ||
return err | ||
} | ||
|
||
|
@@ -149,7 +213,14 @@ | |
|
||
// URI binds the route parameters into the struct, map[string]string and map[string][]string. | ||
func (b *Bind) URI(out any) error { | ||
if err := b.returnErr(binder.URIBinder.Bind(b.ctx.Route().Params, b.ctx.Params, out)); err != nil { | ||
bind := binder.GetFromThePool[*binder.URIBinding](&binder.URIBinderPool) | ||
|
||
// Reset & put binder | ||
defer func() { | ||
bind.Reset() | ||
}() | ||
|
||
if err := b.returnErr(bind.Bind(b.ctx.Route().Params, b.ctx.Params, out)); err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification URI binding has test coverage, but pool and Reset behavior needs testing The codebase already has URI binding tests in
🔗 Analysis chainAdd test coverage for URI binding The URI binding implementation looks correct but lacks test coverage. Please add tests to verify the behavior. 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Check existing test coverage for URI binding
# Look for existing tests
rg -l "TestBind.*URI" .
# Look for URI binding usage patterns to help with test cases
ast-grep --pattern 'func $test($t *testing.T) {
$$$
Bind().URI($$$)
$$$
}'
Length of output: 108 Script: #!/bin/bash
# Let's try a broader search for URI binding tests and implementation
# Search for URI binding test files
rg -l "Test.*URI.*Bind|Bind.*URI" .
# Search for URI binding implementation and usage
rg -l "URIBinding|URIBinder" .
# Look for specific test patterns with URIBinding
ast-grep --pattern 'func Test$_($_) {
$$$
URIBinding
$$$
}'
# Check for any test files that might test URI binding functionality
fd ".*_test.go$" --exec grep -l "URI.*Bind\|Bind.*URI" {}
Length of output: 483 Script: #!/bin/bash
# Let's examine the actual URI binding test content
# Check URI binding test content
rg "func Test.*URI.*Bind|func.*TestBind.*URI" -A 10 ./binder/uri_test.go ./bind_test.go
# Look for specific URI binding test cases
rg "URIBinding" -B 2 -A 5 ./binder/uri_test.go
# Check test coverage for the specific pool usage and Reset functionality
rg "GetFromThePool.*URIBinding|Reset\(\)" -B 2 -A 5 ./binder/uri_test.go ./bind_test.go
Length of output: 2096 🧰 Tools🪛 GitHub Check: codecov/patch[warning] 216-221: bind.go#L216-L221 [warning] 223-223: bind.go#L223 |
||
return err | ||
} | ||
|
||
|
@@ -158,7 +229,15 @@ | |
|
||
// MultipartForm binds the multipart form into the struct, map[string]string and map[string][]string. | ||
func (b *Bind) MultipartForm(out any) error { | ||
if err := b.returnErr(binder.FormBinder.BindMultipart(b.ctx.RequestCtx(), out)); err != nil { | ||
bind := binder.GetFromThePool[*binder.FormBinding](&binder.FormBinderPool) | ||
bind.EnableSplitting = b.ctx.App().config.EnableSplittingOnParsers | ||
|
||
// Reset & put binder | ||
defer func() { | ||
bind.Reset() | ||
}() | ||
|
||
if err := b.returnErr(bind.BindMultipart(&b.ctx.RequestCtx().Request, out)); err != nil { | ||
return err | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Request() method for type safety.
For consistency and type safety, use the abstracted
Request()
method instead of directly accessingRequestCtx().Request
.Apply this change to all affected methods:
Also applies to: 144-144, 218-218