-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Adding in a check for routes with just / #215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding in a check for routes with just / #215
Conversation
Thanks for submitting this. Will review tomorrow! |
If it helps this is the code I used to test: package main
import (
"fmt"
"log"
"net/http"
"github.com/gorilla/mux"
)
func main() {
router := mux.NewRouter()
adminRouter := router.PathPrefix("/admin").Subrouter()
adminRouter.HandleFunc("", someHandler)
adminRouter.HandleFunc("/", someHandler)
log.Print("Listening on :5000")
httpErr := http.ListenAndServe(":5000", router)
if httpErr != nil {
log.Fatal("ListenAndServe:", httpErr)
}
}
func someHandler(w http.ResponseWriter, r *http.Request) {
fmt.Printf("In the handler\n")
} Running this with my fix should allow you to hit both |
Can you add some additional test cases to this?
This will help prevent any regressions in future. mux has grown a lot over time & I want to make sure the testing story is as robust as it can be. |
@elithrar Just added the extra test cases! |
LGTM - @kisielk? |
LGTM as well. Thanks! |
The code added doesn't seem to make any sense:
Wouldn't that always evaluate to false? I would think you would want to say: |
@scisci the reason that it makes sense (and it's kinda strange) is that if
which is why With all that in mind you are correct that |
OK, guess I'm missing something :) It looked to me like this code would always return false, so it wouldn't catch truly bad templates that don't start with a slash like router.HandleFunc("someNonEmptyRouteWithNoSlash", ...) But I'm new to gorilla so maybe this is on purpose or maybe I'm wrong. |
I think I agree with @scisci ... looking at it again I can't seem to make this logic make sense in my head, unless I am missing something. |
After playing with it in the playground it's broken. |
This should fix #79.
Looking for feedback!