Fixed incorrect path traversal

This commit is contained in:
2025-03-01 14:27:26 +01:00
parent 20945fb424
commit 63655425af
3 changed files with 42 additions and 6 deletions

17
Tree.go
View File

@ -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