Skip to content
Myr

fix(tree): Keep panic infos consistent when wildcard type build faild (#4077)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Xinyu Kuo · committed by GitHub · parent 9d11234 · Browse files · 3 files+27 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+27 added−2 removed

  • other:+27 added−2 removed

3 files+27 added−2 removed

modified:.github/workflows/gin.yml+1 added-1 removed
modified:tree_test.go+25 added
991 unmodified lines
992 t.Fatalf("%s should be %t but got %v", route, valid, recv)993 }994 }995}996997func TestWildcardInvalidSlash(t *testing.T) {998 const panicMsgPrefix = "no / before catch-all in path"9991000 routes := map[string]bool{1001 "/foo/bar": true,1002 "/foo/x*zy": false,1003 "/foo/b*r": false,1004 }10051006 for route, valid := range routes {1007 tree := &node{}1008 recv := catchPanic(func() {1009 tree.addRoute(route, nil)1010 })10111012 if recv == nil != valid {1013 t.Fatalf("%s should be %t but got %v", route, valid, recv)1014 }10151016 if rs, ok := recv.(string); recv != nil && (!ok || !strings.HasPrefix(rs, panicMsgPrefix)) {1017 t.Fatalf(`"Expected panic "%s" for route '%s', got "%v"`, panicMsgPrefix, route, recv)1018 }1019 }1020}
modified:tree.go+1 added-1 removed
367 unmodified lines
368 }369370 // currently fixed width 1 for '/'371 i--372 if path[i] != '/' {372 if i < 0 || path[i] != '/' {373 panic("no / before catch-all in path '" + fullPath + "'")374 }375376 n.path = path[:i]
524 unmodified lines