Fixes path order dependent response when a nil handler is defined for a route#517
Fixes path order dependent response when a nil handler is defined for a route#517rkilingr wants to merge 6 commits intogorilla:mainfrom
Conversation
mux_test.go
Outdated
| t.Fatalf("Expected status code 200 (got %d)", w.Code) | ||
| } | ||
|
|
||
| reversedPathRouter := NewRouter() |
There was a problem hiding this comment.
Break these into subtests - e.g.
t.Run("Test handler ordering", func(t *testing.T) {
// test
})
t.Run("Test reversed handler ordering", func(t *testing.T) {
// test
})
I would also add additional test cases:
- Test ordering where handlers have the same method & path, but a different handler (expected: the first handler added is the one executed)
- Same path, different methods (no path variables)
- Same as Host() with a port fails to match when the host is supplied in the HTTP Host: header #2, but with middleware
mux_test.go
Outdated
| reversedPathRouter := NewRouter() | ||
| reversedPathRouter.Path("/a/{a}").Handler(http.HandlerFunc(handler)).Methods(http.MethodGet) | ||
| reversedPathRouter.Path("/a/b").Handler(nil).Methods(http.MethodOptions) | ||
| reversedPathRouter.Use(MiddlewareFunc(testOptionsMiddleWare)) |
There was a problem hiding this comment.
This should be before the paths are added.
mux_test.go
Outdated
| reversedPathRouter.Path("/a/b").Handler(nil).Methods(http.MethodOptions) | ||
| reversedPathRouter.Use(MiddlewareFunc(testOptionsMiddleWare)) | ||
|
|
||
| w = NewRecorder() |
There was a problem hiding this comment.
Make it a subtest (as above) and call newRequest again to separate it.
|
@rkilingr - did you still want to complete this? |
|
@rkilingr - just following up again if you're still keen on completing this? |
Apologies for the huge delay. Was not active last year, will be updating the PR |
|
Hi @rkilingr - quick follow-up - are you interested in getting this merged? Will do a review again if existing comments are addressed. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #517 +/- ##
==========================================
+ Coverage 78.01% 78.19% +0.17%
==========================================
Files 5 5
Lines 887 885 -2
==========================================
Hits 692 692
+ Misses 140 138 -2
Partials 55 55 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@coreydaley @jackgris @rkilingr this change really needs to get merged in tbh. im debugging my routing and the |
|
Hello @pcfreak30 Thanks for the work! I have just started looking into this issue. Would you be able to do a rebase to eliminate the conflicts? |
Um, this isn't my PR so im not sure what you mean.... Though I do want to see this bug fixed :P. |
|
@pcfreak30 my bad. I mixed up two different communications. |
Fixes #515
Summary of Changes
handler != nilcondition only for setting the matched handler, not for clearing Method mismatch errornil