Skip to content

Conversation

@lewiscollard
Copy link
Contributor

Fixes #273.

Previously, Path used urljoin to prepend a forward slash to the path. But urljoin, for no good reason I can see, breaks if you have two slashes in a path:

>>> from urllib.parse import urljoin
>>> urljoin("/", "oh//no")
'/oh/no'

This manifests itself as respx asserting that routes were not called if they contained two forward slashes in the path part. Fix this by just adding a "/" if it's not there, which is what this was trying to do in the first place.

Fixes lundberg#273.

Previously, `Path` used `urljoin` to prepend a forward slash to the
path. But `urljoin` is broken for no good reason:

    >>> from urllib.parse import urljoin
    >>> urljoin("/", "oh//no")
    '/oh/no'

Fix this by just adding a "/" if it's not there, which is what this
was trying to do in the first place.
Copy link

@sparrowt sparrowt left a comment

Choose a reason for hiding this comment

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

This looks good to me, any thoughts @lundberg?

@lundberg
Copy link
Owner

Looks good! Thanks @lewiscollard

@codecov
Copy link

codecov bot commented Nov 17, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (b3d8e9d) to head (dfd38b4).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #302   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           22        22           
  Lines         2933      2934    +1     
  Branches       199       200    +1     
=========================================
+ Hits          2933      2934    +1     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lundberg lundberg merged commit c39612a into lundberg:master Nov 17, 2025
10 checks passed
@sparrowt
Copy link

Thanks @lundberg! Would there be any chance of a new release please? Though I fully appreciate life can be busy.
0.22.0...master

We have a test that fails intermittently when there are 2 sequential slashes in a base64 value that ends up in the URL (don't ask...!)

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.

respx_mock doesn't handle // in the path-section of URLs.

3 participants