Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcc5f536

Browse files
mattdhollowaySamMorrowDrums
authored andcommitted
refine pattern matching logic to prioritise non-wildcard handlers in multiHandlerTransport
1 parent27c1051 commitcc5f536

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

‎pkg/github/helper_test.go‎

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,20 +582,45 @@ func (m *multiHandlerTransport) RoundTrip(req *http.Request) (*http.Response, er
582582
returnexecuteHandler(handler,req),nil
583583
}
584584

585-
// Then try pattern matching
585+
// Then try pattern matching, prioritizing patterns without wildcards
586+
// This is important because wildcard patterns like /{owner}/{repo}/{sha}/{path:.*}
587+
// can incorrectly match API paths like /repos/owner/repo/pulls/42
588+
varwildcardPatternstring
589+
varwildcardHandler http.HandlerFunc
590+
586591
forpattern,handler:=rangem.handlers {
587592
ifpattern=="" {
588593
continue// Skip catch-all
589594
}
590595
parts:=strings.SplitN(pattern," ",2)
591-
iflen(parts)==2 {
592-
method,pathPattern:=parts[0],parts[1]
593-
ifreq.Method==method&&matchPath(pathPattern,req.URL.Path) {
596+
iflen(parts)!=2 {
597+
continue
598+
}
599+
method,pathPattern:=parts[0],parts[1]
600+
ifreq.Method!=method {
601+
continue
602+
}
603+
604+
// Check if this pattern contains a wildcard like {path:.*}
605+
isWildcard:=strings.Contains(pathPattern,":.*}")
606+
607+
ifmatchPath(pathPattern,req.URL.Path) {
608+
ifisWildcard {
609+
// Save wildcard match for later, prefer non-wildcard patterns
610+
wildcardPattern=pattern
611+
wildcardHandler=handler
612+
}else {
613+
// Non-wildcard pattern takes priority
594614
returnexecuteHandler(handler,req),nil
595615
}
596616
}
597617
}
598618

619+
// If we found a wildcard match but no specific match, use it
620+
ifwildcardPattern!=""&&wildcardHandler!=nil {
621+
returnexecuteHandler(wildcardHandler,req),nil
622+
}
623+
599624
// No handler found
600625
return&http.Response{
601626
StatusCode:http.StatusNotFound,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp