starlette icon indicating copy to clipboard operation
starlette copied to clipboard

fix: regex inside function get_route_path to remove root_path

Open gabriel-f-santos opened this issue 9 months ago • 1 comments

Issue: https://github.com/encode/starlette/issues/2599 Discussion: https://github.com/encode/starlette/discussions/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

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

gabriel-f-santos avatar May 22 '24 16:05 gabriel-f-santos