fix maxParams bug (#2166)
This commit is contained in:
		
							
								
								
									
										4
									
								
								tree.go
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								tree.go
									
									
									
									
									
								
							@ -357,6 +357,10 @@ func (n *node) insertChild(numParams uint8, path string, fullPath string, handle
 | 
				
			|||||||
				maxParams: 1,
 | 
									maxParams: 1,
 | 
				
			||||||
				fullPath:  fullPath,
 | 
									fullPath:  fullPath,
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
								// update maxParams of the parent node
 | 
				
			||||||
 | 
								if n.maxParams < 1 {
 | 
				
			||||||
 | 
									n.maxParams = 1
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
			n.children = []*node{child}
 | 
								n.children = []*node{child}
 | 
				
			||||||
			n.indices = string(path[i])
 | 
								n.indices = string(path[i])
 | 
				
			||||||
			n = child
 | 
								n = child
 | 
				
			||||||
 | 
				
			|||||||
@ -368,6 +368,13 @@ func TestTreeCatchAllConflictRoot(t *testing.T) {
 | 
				
			|||||||
	testRoutes(t, routes)
 | 
						testRoutes(t, routes)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestTreeCatchMaxParams(t *testing.T) {
 | 
				
			||||||
 | 
						tree := &node{}
 | 
				
			||||||
 | 
						var route = "/cmd/*filepath"
 | 
				
			||||||
 | 
						tree.addRoute(route, fakeHandler(route))
 | 
				
			||||||
 | 
						checkMaxParams(t, tree)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TestTreeDoubleWildcard(t *testing.T) {
 | 
					func TestTreeDoubleWildcard(t *testing.T) {
 | 
				
			||||||
	const panicMsg = "only one wildcard per path segment is allowed"
 | 
						const panicMsg = "only one wildcard per path segment is allowed"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user