The url.RawPath used when engine.UseRawPath is set to true. (#810)
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
package gin
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
@@ -363,7 +364,7 @@ func (n *node) insertChild(numParams uint8, path string, fullPath string, handle
|
||||
// If no handle can be found, a TSR (trailing slash redirect) recommendation is
|
||||
// made if a handle exists with an extra (without the) trailing slash for the
|
||||
// given path.
|
||||
func (n *node) getValue(path string, po Params) (handlers HandlersChain, p Params, tsr bool) {
|
||||
func (n *node) getValue(path string, po Params, unescape bool) (handlers HandlersChain, p Params, tsr bool) {
|
||||
p = po
|
||||
walk: // Outer loop for walking the tree
|
||||
for {
|
||||
@@ -406,7 +407,15 @@ walk: // Outer loop for walking the tree
|
||||
i := len(p)
|
||||
p = p[:i+1] // expand slice within preallocated capacity
|
||||
p[i].Key = n.path[1:]
|
||||
p[i].Value = path[:end]
|
||||
val := path[:end]
|
||||
if unescape {
|
||||
var err error
|
||||
if p[i].Value, err = url.QueryUnescape(val); err != nil {
|
||||
p[i].Value = val // fallback, in case of error
|
||||
}
|
||||
} else {
|
||||
p[i].Value = val
|
||||
}
|
||||
|
||||
// we need to go deeper!
|
||||
if end < len(path) {
|
||||
@@ -440,7 +449,14 @@ walk: // Outer loop for walking the tree
|
||||
i := len(p)
|
||||
p = p[:i+1] // expand slice within preallocated capacity
|
||||
p[i].Key = n.path[2:]
|
||||
p[i].Value = path
|
||||
if unescape {
|
||||
var err error
|
||||
if p[i].Value, err = url.QueryUnescape(path); err != nil {
|
||||
p[i].Value = path // fallback, in case of error
|
||||
}
|
||||
} else {
|
||||
p[i].Value = path
|
||||
}
|
||||
|
||||
handlers = n.handlers
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user