Skip to content
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

Adds a test to ensure URL paths are lower case #68

Merged
merged 1 commit into from
Jan 14, 2020

Conversation

m1kola
Copy link
Contributor

@m1kola m1kola commented Jan 13, 2020

Fixes #64

Copy link
Member

@jim-minter jim-minter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just nits, really - looks good

f := &frontend{}

fakeRouter := mux.NewRouter()
f.unauthenticatedRoutes(fakeRouter.NewRoute().Subrouter())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be up for seeing the router setup in frontend.Run pulled out into a nonexported method to avoid the duplication here, wdyt?


// Ignore the error: it can occur when a route has no path,
// but there is no way to check it here
if err == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if err != nil { continue } reduces indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a loop, but I changed it in a similar way with return nil

if err == nil {
cleanPathTemplate := varCleanupRe.ReplaceAllString(pathTemplate, "")
if cleanPathTemplate != strings.ToLower(cleanPathTemplate) {
t.Fatal(pathTemplate)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit t.Error() will allow someone to see all the faulty routes in one go.

f.s = &http.Server{
Handler: middleware.Lowercase(r),
Handler: middleware.Lowercase(f.setupRouter()),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit for next time, might be worth getting middleware.Lowercase() in setupRouter too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jim-minter yeah, I was thinking about it, but decided to keep it here, because I wasn't sure why it wasn't in router itself initially. My guess was: a middleware added like r.Use(middleware.Lowercase) will only be called on a route match, but we might want lowercase 404s.

@jim-minter jim-minter merged commit 9f98531 into Azure:master Jan 14, 2020
@m1kola m1kola deleted the URL_paths_are_lower_case branch January 14, 2020 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add unit test to ensure URL paths are lower case
2 participants