Fixed incorrect path traversal
This commit is contained in:
17
Tree.go
17
Tree.go
@ -92,10 +92,12 @@ func (tree *Tree[T]) Lookup(path string) (T, []Parameter) {
|
||||
// LookupNoAlloc finds the data for the given path without using any memory allocations.
|
||||
func (tree *Tree[T]) LookupNoAlloc(path string, addParameter func(key string, value string)) T {
|
||||
var (
|
||||
i uint
|
||||
wildcardPath string
|
||||
wildcard *treeNode[T]
|
||||
node = &tree.root
|
||||
i uint
|
||||
parameterPath string
|
||||
wildcardPath string
|
||||
parameter *treeNode[T]
|
||||
wildcard *treeNode[T]
|
||||
node = &tree.root
|
||||
)
|
||||
|
||||
// Skip the first loop iteration if the starting characters are equal
|
||||
@ -115,6 +117,8 @@ begin:
|
||||
wildcardPath = path[i:]
|
||||
}
|
||||
|
||||
parameter = node.parameter
|
||||
parameterPath = path[i:]
|
||||
char := path[i]
|
||||
|
||||
if char >= node.startIndex && char < node.endIndex {
|
||||
@ -178,6 +182,11 @@ begin:
|
||||
// node: /|*any
|
||||
// path: /|image.png
|
||||
notFound:
|
||||
if parameter != nil {
|
||||
addParameter(parameter.prefix, parameterPath)
|
||||
return parameter.data
|
||||
}
|
||||
|
||||
if wildcard != nil {
|
||||
addParameter(wildcard.prefix, wildcardPath)
|
||||
return wildcard.data
|
||||
|
Reference in New Issue
Block a user