Allow relative base URI in merge.#186
Conversation
|
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: |
|
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 |
|
@HoneyryderChuck do you want to work on this PR? Happy to pass it over to you. |
|
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. |
ec356e6 to
5b7c0db
Compare
There was a problem hiding this comment.
Pull request overview
Adds an opt-in path-merge capability for cases where the base URI is relative, enabling intermediate URI path computations without requiring an absolute base.
Changes:
- Extend
URI::Generic#mergewith anallow_relativeboolean parameter to permit merging when the base URI is relative. - Update
URI::Generic#mergedocumentation to describe the new behavior and parameter. - Add tests covering relative-base merge behavior (including
..traversal and leading/handling).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
lib/uri/generic.rb |
Adds allow_relative parameter to merge and updates docstring to describe merging relative bases. |
test/uri/test_generic.rb |
Adds unit tests asserting behavior when merging relative base URIs with allow_relative enabled/disabled. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # +oth+:: | ||
| # URI or String | ||
| # +allow_relative+:: | ||
| # Boolean (false by default) |
| def merge(oth, allow_relative = false) | ||
| rel = parser.__send__(:convert_to_uri, oth) |
| # +oth+:: | ||
| # URI or String | ||
| # +allow_relative+:: | ||
| # Boolean (false by default) |
| def merge(oth, allow_relative = false) | ||
| rel = parser.__send__(:convert_to_uri, oth) |
I have needed this feature on several occasions, for example, when handling intermediate URI path computations.