Skip to content

Fix path normalization of index route#347

Merged
Nehliin merged 1 commit intotower-rs:masterfrom
cassaundra:normalize-path-index
Apr 11, 2023
Merged

Fix path normalization of index route#347
Nehliin merged 1 commit intotower-rs:masterfrom
cassaundra:normalize-path-index

Conversation

@cassaundra
Copy link
Copy Markdown
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 cassaundra force-pushed the normalize-path-index branch from 87b44d8 to 4b7fa0e Compare March 24, 2023 01:01
@cassaundra
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.
@cassaundra cassaundra force-pushed the normalize-path-index branch from 4b7fa0e to 13dc41c Compare April 1, 2023 19:01
Copy link
Copy Markdown
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
Copy Markdown
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
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