Update router.go

pull/3230/head
Juan Calderon-Perez 2025-03-10 21:57:09 -04:00 committed by GitHub
parent 21e42ad126
commit 006bd188e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 2 deletions

View File

@ -338,6 +338,7 @@ func (app *App) register(methods []string, pathRaw string, group *Group, handler
if pathRaw[0] != '/' {
pathRaw = "/" + pathRaw
}
pathPretty := pathRaw
if !app.config.CaseSensitive {
pathPretty = utils.ToLower(pathPretty)
@ -345,11 +346,10 @@ func (app *App) register(methods []string, pathRaw string, group *Group, handler
if !app.config.StrictRouting && len(pathPretty) > 1 {
pathPretty = utils.TrimRight(pathPretty, '/')
}
pathClean := RemoveEscapeChar(pathPretty)
pathClean := RemoveEscapeChar(pathPretty)
parsedRaw := parseRoute(pathRaw, app.customConstraints...)
parsedPretty := parseRoute(pathPretty, app.customConstraints...)
isMount := group != nil && group.app != app
for _, method := range methods {
@ -358,6 +358,12 @@ func (app *App) register(methods []string, pathRaw string, group *Group, handler
panic(fmt.Sprintf("add: invalid http method %s\n", method))
}
// Duplicate Route Handling
if app.routeExists(method, pathRaw) {
matchPathFunc := func(r *Route) bool { return r.Path == pathRaw }
app.deleteRoute([]string{method}, matchPathFunc)
}
isUse := method == methodUse
isStar := pathClean == "/*"
isRoot := pathClean == "/"