with_path: preserve bare-relative status for netloc-less URLs (#1770)#1781
Draft
HrachShah wants to merge 2 commits into
Draft
with_path: preserve bare-relative status for netloc-less URLs (#1770)#1781HrachShah wants to merge 2 commits into
HrachShah wants to merge 2 commits into
Conversation
…bs#1770) URL('foo/bar').with_path('abs') used to silently return URL('/abs'), turning a bare-relative reference into an absolute-path reference. The prepended slash changed how the URL resolved against any base, so the bug surfaced only after the user joined the result back to a parent. Only prepend the leading slash when the URL has a netloc. URL strings without a scheme and without an authority stay bare-relative across with_path; the explicit '/abs' form still gets the leading slash as before. Add three regression tests in tests/test_url.py: one for the basic shape of the bug, one for the explicit slash form, and one for the round-trip with .join()
for more information, see https://pre-commit.ci
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1781 +/- ##
=======================================
Coverage 99.86% 99.86%
=======================================
Files 21 21
Lines 4310 4327 +17
Branches 252 252
=======================================
+ Hits 4304 4321 +17
Misses 4 4
Partials 2 2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What do these changes do?
Preserve the bare-relative status of a URL across
with_pathwhen the new path does not start with/. The leading/is now only added for URLs that have a netloc, soURL("foo/bar").with_path("abs")returnsURL("abs")instead of silently promoting the result to an absolute-path reference.Are there changes in behavior for the user?
Yes. URLs without scheme and without authority stay bare-relative across
with_pathinstead of being silently promoted. Callers that want the old behavior can pass an explicit/absform, which still gets the leading slash.Is it a substantial burden for the maintainers to support this?
No. The new branch only triggers when the caller passes a path without a leading
/to a URL with no netloc, which is a narrow and previously-buggy path.Related issue number
Fixes #1770
Checklist
CONTRIBUTORS.txtCHANGES/folderAgent run details (optional, for reviewers)
Tests:
python3 -m pytest tests/test_url.py -k "with_path" -p no:cacheprovider --no-cov-> 19 passedWider suite:
python3 -m pytest tests/ yarl/ -p no:cacheprovider --no-cov-> 1457 passed, 101 skipped, 4 xfailedSpellcheck:
make doc-spelling-> my fragment passes; the 8 remaining misspellings are in pre-existing files unrelated to this change.Drafted with Zo Bot; reviewed by HrachShah.