Skip to content

Commit 5619769

Browse files
committed
Fix path matching logic for ErrorHandler assignment
1 parent 4f7efbe commit 5619769

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

app.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,9 +1041,13 @@ func (app *App) ErrorHandler(ctx *Ctx, err error) error {
10411041
mountedPrefixParts int
10421042
)
10431043

1044+
normalizedPath := utils.AddTrailingSlash(ctx.Path())
1045+
10441046
for _, prefix := range app.mountFields.appListKeys {
10451047
subApp := app.mountFields.appList[prefix]
1046-
if prefix != "" && strings.HasPrefix(ctx.Path(), prefix) {
1048+
normalizedPrefix := utils.AddTrailingSlash(prefix)
1049+
1050+
if prefix != "" && strings.HasPrefix(normalizedPath, normalizedPrefix) {
10471051
parts := len(strings.Split(prefix, "/"))
10481052
if mountedPrefixParts <= parts {
10491053
if subApp.configured.ErrorHandler != nil {

utils/strings.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
package utils
66

7+
import "strings"
8+
79
// ToLower converts ascii string to lower-case
810
func ToLower(b string) string {
911
res := make([]byte, len(b))
@@ -73,3 +75,11 @@ func EqualFold(b, s string) bool {
7375
}
7476
return true
7577
}
78+
79+
func AddTrailingSlash(s string) string {
80+
if strings.HasSuffix(s, "/") {
81+
return s
82+
}
83+
84+
return s + "/"
85+
}

0 commit comments

Comments
 (0)