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: use re.match instead of re.search for mounted app path (#3501) #3511

Merged
merged 4 commits into from
May 25, 2024

Conversation

0xE111
Copy link
Contributor

@0xE111 0xE111 commented May 18, 2024

Description

See #3501 for detailed description.

TL;DR: When mounting an app, path resolution uses re.search instead or re.match, thus mounted app matches any path which contains mount path.

Original code used re.search and had explicit "sub-path match" (path[match.start() : match.end()]) which makes me think there was some reasoning behind re.search but tbh I don't get it:

if mount_paths_regex and (match := mount_paths_regex.search(path)):
    mount_path = path[match.start() : match.end()]

Closes

Fixes #3501

@0xE111 0xE111 requested review from a team as code owners May 18, 2024 08:47
@github-actions github-actions bot added area/private-api This PR involves changes to the privatized API size: small type/bug pr/external Triage Required 🏥 This requires triage labels May 18, 2024
Copy link

codecov bot commented May 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.28%. Comparing base (17db66b) to head (1ceb480).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3511   +/-   ##
=======================================
  Coverage   98.28%   98.28%           
=======================================
  Files         328      328           
  Lines       14882    14882           
  Branches     2367     2367           
=======================================
  Hits        14627    14627           
  Misses        116      116           
  Partials      139      139           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@peterschutt
Copy link
Contributor

Original code used re.search and had explicit "sub-path match" (path[match.start() : match.end()]) which makes me think there was some reasoning behind re.search but tbh I don't get it:

I'm trying to figure this out for myself - its almost as though it is designed to match against a sub-path and then extract the mount path component.. but why.. I'm not sure.. I'll spend more time trying to figure it out. On the plus side, your implementation doesn't break any tests - so maybe it is just a weirdness that exists due to code evolution or whatever, but I'd like to take a bit of time to think it through.

@peterschutt
Copy link
Contributor

Original code used re.search and had explicit "sub-path match" (path[match.start() : match.end()]) which makes me think there was some reasoning behind re.search but tbh I don't get it:

if mount_paths_regex and (match := mount_paths_regex.search(path)):
    mount_path = path[match.start() : match.end()]

@provinzkraut My best guess with this is that it was required before we started handling root_path in #3039. That is, before that PR, the path we matched the mount path against, may still have had the root path prepended to it, and so indexing both ends of the slice would have effectively stripped the root path from the path we pass through to the mounted app.. this is my best guess.. any thoughts?

Copy link
Contributor

@peterschutt peterschutt left a comment

Choose a reason for hiding this comment

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

Thanks @0xE111 - I'm just waiting on another set of eyes on that path slicing business before we merge.

@provinzkraut provinzkraut enabled auto-merge (squash) May 25, 2024 08:20
@provinzkraut provinzkraut merged commit 702dd84 into litestar-org:main May 25, 2024
24 checks passed
Copy link

Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/3511

@provinzkraut
Copy link
Member

@provinzkraut My best guess with this is that it was required before we started handling root_path in #3039. That is, before that PR, the path we matched the mount path against, may still have had the root path prepended to it, and so indexing both ends of the slice would have effectively stripped the root path from the path we pass through to the mounted app.. this is my best guess.. any thoughts?

Can't come up with a better explanation, so I'd say it's okay to merge this as is!

@provinzkraut
Copy link
Member

@all-contributors add @0xE111 for code

Copy link
Contributor

@provinzkraut

I've put up a pull request to add @0xE111! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/private-api This PR involves changes to the privatized API pr/external pr/internal size: small Triage Required 🏥 This requires triage type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: mounted app path interferes with regular paths
3 participants