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

Ensure accurate root_path removal in get_route_path function #2600

Merged
merged 5 commits into from
Sep 1, 2024

Conversation

gabriel-f-santos
Copy link
Contributor

Issue: #2599
Discussion: #2495

Summary

Change regex used to remove root_path to consider only the root path without match simillar endpoint that contains the root_path as substring.
ex:

root_path = "product"
scope["path"] = "products/all"

before:

re.sub(r"^" + root_path, "", scope["path"]) -> 's/all'

after:

re.sub(r"^" + root_path + r"(?=/|$)", "", scope["path"]) -> '/products/all'

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

@Kludex
Copy link
Member

Kludex commented Aug 21, 2024

Is there a way we can use removeprefix instead?

@Kludex Kludex changed the title fix: regex inside function get_route_path to remove root_path Ensure accurate root_path removal in get_route_path function Sep 1, 2024
@Kludex Kludex merged commit 1131b3c into encode:master Sep 1, 2024
6 checks passed
nixroxursox pushed a commit to nixroxursox/starlette that referenced this pull request Sep 30, 2024
…ode#2600)

* fix: regex inside function get_route_path to remove root_path

* fix: apply format ruff

* fix: mypy

---------

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
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.

2 participants