Skip to content

Conversation

@ioquatix
Copy link
Member

I have needed this feature on several occasions, for example, when handling intermediate URI path computations.

@ioquatix ioquatix requested a review from hsbt October 22, 2025 07:28
@ioquatix
Copy link
Member Author

ioquatix commented Oct 22, 2025

I checked, and Python appears to support this without any extra flag:

#!/usr/bin/env python3
from urllib.parse import urljoin

bases = [
    'a/b/c',         # relative base (no trailing slash)
    'a/b/c/',        # relative base (trailing slash)
    '/a/b/c',        # absolute path base
    'http://ex/a/b/c' # absolute URL base
]
rels = ['d/e', '../x', '/z', '']

for b in bases:
    print(f"\nBase: {b!r}")
    for r in rels:
        print(f"  urljoin({b!r}, {r!r}) -> {urljoin(b, r)!r}")

This would be the ideal case for me (no extra flag).

If we can be compatible with Python, we just need to delete:

      unless self.absolute?
        raise BadURIError, "both URI are relative"
      end

@HoneyryderChuck
Copy link
Contributor

thx for the patch @ioquatix 🙏 I report this recently here, and was going to patch it myself until I saw your PR.

IMO I think that uri should do the same as python, i.e. if the merge is relative (the origin is the same), then the user info should be retained. Bear in mind I say "origin", as in, if the hostname is the same but any of the scheme or port does, then the library can assume that the merge is unsafe and the userinfo shall be reset.

@ioquatix
Copy link
Member Author

@HoneyryderChuck do you want to work on this PR? Happy to pass it over to you.

@HoneyryderChuck
Copy link
Contributor

I think I was too tired when I saw your PR, I don't think it has anything to do with the issue I opened, which is about wiping out the userinfo when certain parameters update. sorry about that.

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