This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: urljoin allow_fragments doesn't work
Type: Stage: resolved
Components: Documentation Versions: Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: ColonelThirtyTwo, docs@python, georg.brandl, orsenthil, python-dev
Priority: normal Keywords:

Created on 2014-10-09 16:00 by ColonelThirtyTwo, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg228877 - (view) Author: Alex Parrill (ColonelThirtyTwo) Date: 2014-10-09 16:00
Passing False to the allow_fragments argument to urljoin doesn't remove fragments.

Is this a bug, or am I misunderstanding the allow_fragments parameter? It's not perfectly clear what "fragment identifiers are not allowed" means (strips them out? throws an error?)

I'm running this on XUbuntu 14.04.01.

$ python3
Python 3.4.0 (default, Apr 11 2014, 13:05:11) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from urllib.parse import urljoin
>>> urljoin("http://localhost:8000/foo.html", "bar.html#baz", allow_fragments=False)
'http://localhost:8000/bar.html#baz'
msg228881 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2014-10-09 16:50
The "not allowed" should be clarified.  What is meant is that if allow_fragments is false, a fragment is parsed as part of the path.

This doesn't make a difference for urljoin if the fragment is part of the second part.  It does make a difference for the first part:

>>> urljoin('http://www.example.com/#frag/', 'foo#bar', allow_fragments=True)
'http://www.example.com/foo#bar'

>>> urljoin('http://www.example.com/#frag/', 'foo#bar', allow_fragments=False)
'http://www.example.com/#frag/foo#bar'

For reference, the urlparse() results:

>>> urlparse('http://www.example.com/#frag/', allow_fragments=True)
ParseResult(scheme='http', netloc='www.example.com', path='/', params='', query='', fragment='frag/')

>>> urlparse('http://www.example.com/#frag/', allow_fragments=False)
ParseResult(scheme='http', netloc='www.example.com', path='/#frag/', params='', query='', fragment='')
msg229145 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-10-12 14:14
New changeset 9eed2e7fa764 by Georg Brandl in branch '3.4':
Closes #22586: clarify meaning of allow_fragments in urlparse.
https://hg.python.org/cpython/rev/9eed2e7fa764

New changeset c2eda29a8ccb by Georg Brandl in branch '2.7':
Closes #22586: clarify meaning of allow_fragments in urlparse.
https://hg.python.org/cpython/rev/c2eda29a8ccb
History
Date User Action Args
2022-04-11 14:58:08adminsetgithub: 66776
2014-10-12 14:14:26python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg229145

resolution: fixed
stage: resolved
2014-10-09 16:50:50georg.brandlsetversions: + Python 2.7, Python 3.5
nosy: + docs@python, georg.brandl, orsenthil

messages: + msg228881

assignee: docs@python
components: + Documentation, - Library (Lib)
2014-10-09 16:00:33ColonelThirtyTwocreate