mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-20 00:02:16 +08:00
chore: Add RemoveExtraSlash flag
This commit is contained in:
parent
231ff00d1f
commit
7e489984dd
8
gin.go
8
gin.go
@ -97,6 +97,10 @@ type Engine struct {
|
|||||||
// method call.
|
// method call.
|
||||||
MaxMultipartMemory int64
|
MaxMultipartMemory int64
|
||||||
|
|
||||||
|
// RemoveExtraSlash a parameter can be parsed from the URL even with extra slashes.
|
||||||
|
// See the PR #1817 and issue #1644
|
||||||
|
RemoveExtraSlash bool
|
||||||
|
|
||||||
delims render.Delims
|
delims render.Delims
|
||||||
secureJsonPrefix string
|
secureJsonPrefix string
|
||||||
HTMLRender render.HTMLRender
|
HTMLRender render.HTMLRender
|
||||||
@ -134,6 +138,7 @@ func New() *Engine {
|
|||||||
ForwardedByClientIP: true,
|
ForwardedByClientIP: true,
|
||||||
AppEngine: defaultAppEngine,
|
AppEngine: defaultAppEngine,
|
||||||
UseRawPath: false,
|
UseRawPath: false,
|
||||||
|
RemoveExtraSlash: false,
|
||||||
UnescapePathValues: true,
|
UnescapePathValues: true,
|
||||||
MaxMultipartMemory: defaultMultipartMemory,
|
MaxMultipartMemory: defaultMultipartMemory,
|
||||||
trees: make(methodTrees, 0, 9),
|
trees: make(methodTrees, 0, 9),
|
||||||
@ -385,7 +390,10 @@ func (engine *Engine) handleHTTPRequest(c *Context) {
|
|||||||
rPath = c.Request.URL.RawPath
|
rPath = c.Request.URL.RawPath
|
||||||
unescape = engine.UnescapePathValues
|
unescape = engine.UnescapePathValues
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if engine.RemoveExtraSlash {
|
||||||
rPath = cleanPath(rPath)
|
rPath = cleanPath(rPath)
|
||||||
|
}
|
||||||
|
|
||||||
// Find root of the tree for the given HTTP method
|
// Find root of the tree for the given HTTP method
|
||||||
t := engine.trees
|
t := engine.trees
|
||||||
|
@ -263,6 +263,7 @@ func TestRouteParamsByNameWithExtraSlash(t *testing.T) {
|
|||||||
lastName := ""
|
lastName := ""
|
||||||
wild := ""
|
wild := ""
|
||||||
router := New()
|
router := New()
|
||||||
|
router.RemoveExtraSlash = true
|
||||||
router.GET("/test/:name/:last_name/*wild", func(c *Context) {
|
router.GET("/test/:name/:last_name/*wild", func(c *Context) {
|
||||||
name = c.Params.ByName("name")
|
name = c.Params.ByName("name")
|
||||||
lastName = c.Params.ByName("last_name")
|
lastName = c.Params.ByName("last_name")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user