Repository navigation
urljoin() undocumented behavior change in Python 3.14. #125926
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Oct 24, 2024 I'm assuming this is bug fixed by #123273.
Sorry, I meant this might be caused by it.
- addedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory3.14bugs and security fixesbugs and security fixes
on Oct 24, 2024 Sorry, I meant this might be caused by it.
I can bisect and confirm (or not) during the weekend.
Yes, git bisect points to fc897fc from #123273.
fc897fcc01964649f023e0baa4c95d142e4e8a10 is the first bad commit commit fc897fcc01964649f023e0baa4c95d142e4e8a10 Date: Sat Aug 31 12:42:08 2024 +0300 gh-76960: Fix urljoin() and urldefrag() for URIs with empty components (GH-123273) * urljoin() with relative reference "?" sets empty query and removes fragment. * Preserve empty components (authority, params, query, fragment) in urljoin(). * Preserve empty components (authority, params, query) in urldefrag(). Also refactor the code and get rid of double _coerce_args() and _coerce_result() calls in urljoin(), urldefrag(), urlparse() and urlunparse(). Lib/test/test_urlparse.py | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------- Lib/urllib/parse.py | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------ Misc/NEWS.d/next/Library/2024-08-23-22-01-30.gh-issue-76960.vsANPu.rst | 5 +++++ 3 files changed, 140 insertions(+), 52 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2024-08-23-22-01-30.gh-issue-76960.vsANPu.rsturljoin()was updated to match the reference resolution algorithm in RFC 3986, Section 5. But the algorithm requires the base URI to be an absolute URI. This is why there were no tests for relative base URI. Buturljoin()was used with relative base URIs, and it should continue to return sensible result for relative base URI, even if this goes beyond the application of RFC 3986.Reacted by Rene Leonhardt- added a commit that references this issue
on Nov 7, 2024 Another difference is the following:
Python <3.14
>>> urljoin("file:", "/abc") 'file:///abc'Python 3.14.0
>>> urljoin("file:", "/abc") 'file:/abc'Is that expected?
Reacted by Rene LeonhardtYes, this is expected. Use
"file://"if you want to get an URL with an empty (instead of absent) authority.Semantically, "file:/abc" and "file:///abc" are equivalent, the difference is only in the representation, and in 3.14 you can control what representation you want to get by using
"file:"or"file://".
Bug report
Bug description:
Django is tested with the earliest alpha versions. We noticed a behavior change in the
urllib.parse.urljoin()that is used in a few places in Django, e.g. for staticfiles or build-in storages.Python 3.14.0a1:
Python 3.13 and earlier:
Is this an intentional change?
CPython versions tested on:
3.14
Operating systems tested on:
Linux
Linked PRs