Merge pull request #49 from infinite-iroha/fix-router-panic

Fix router panic
This commit is contained in:
WJQSERVER 2025-08-01 09:09:59 +08:00 committed by GitHub
commit 0f4d90faeb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -293,6 +293,12 @@ walk: // 外部循环用于遍历和构建路由树
} }
} }
func (n *node) copyChildren() []*node {
children := make([]*node, len(n.children))
copy(children, n.children)
return children
}
// findWildcard 搜索通配符段并检查名称是否包含无效字符。 // findWildcard 搜索通配符段并检查名称是否包含无效字符。
// 如果未找到通配符,则返回 -1 作为索引。 // 如果未找到通配符,则返回 -1 作为索引。
func findWildcard(path string) (wildcard string, i int, valid bool) { func findWildcard(path string) (wildcard string, i int, valid bool) {
@ -483,10 +489,11 @@ walk: // 外部循环用于遍历路由树
path: prefix + path, // 记录跳过的路径 path: prefix + path, // 记录跳过的路径
node: &node{ // 复制当前节点的状态 node: &node{ // 复制当前节点的状态
path: n.path, path: n.path,
indices: n.indices,
wildChild: n.wildChild, wildChild: n.wildChild,
nType: n.nType, nType: n.nType,
priority: n.priority, priority: n.priority,
children: n.children, children: n.copyChildren(),
handlers: n.handlers, handlers: n.handlers,
fullPath: n.fullPath, fullPath: n.fullPath,
}, },