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

Fix path normalization of index route #347

Merged
merged 1 commit into from
Apr 11, 2023

Conversation

cassaundra
Copy link
Contributor

@cassaundra cassaundra commented Mar 24, 2023

Previously, normalize_path on / would result in an empty string, causing routers to return 404 on the index route. Fix this by defaulting to / if the resultant path would be empty.

Fixes #318.

@cassaundra
Copy link
Contributor Author

I just added an improved implementation which also removes multiple trailing slashes in the case of an index (e.g. //// to /).

Copy link
Collaborator

@Nehliin Nehliin left a comment

Choose a reason for hiding this comment

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

I don't mind the solution of adding a "/" but it feels wrong to do this within a function called remove_trailing_slash. Could this logic be extracted to before calling into the method? If not we should at least rename the function

@cassaundra
Copy link
Contributor Author

How about normalize_trailing_slash?

Previously, `normalize_path` on `/` would result in an empty string, causing
routers to return 404 on the index route. Fix this by defaulting to `/` if the
resultant path would be empty.

Fixes tower-rs#318.
Copy link
Collaborator

@Nehliin Nehliin left a comment

Choose a reason for hiding this comment

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

Thanks

@Nehliin
Copy link
Collaborator

Nehliin commented Apr 11, 2023

Merging this now since it's such a small change overall

@Nehliin Nehliin merged commit 4788a44 into tower-rs:master Apr 11, 2023
11 checks passed
gezihuzi pushed a commit to gezihuzi/tower-http that referenced this pull request Jul 19, 2023
Previously, `normalize_path` on `/` would result in an empty string, causing
routers to return 404 on the index route. Fix this by defaulting to `/` if the
resultant path would be empty.

Fixes tower-rs#318.
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.

Index route returns 404 with NormalizePath middleware
2 participants