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: urllib.parse doesn't work with empty port
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.3, Python 3.4, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: orsenthil, python-dev, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2014-01-15 12:26 by serhiy.storchaka, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
urllib_parse_empty_port.patch serhiy.storchaka, 2014-01-15 12:26 review
Messages (2)
msg208155 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-01-15 12:26
According to RFC 3986 the port subcomponent is defined as zero or more decimal digits delimited from the host by a single colon. I.e. 'python.org:' is valid (but not normalized) form. Empty port is equivalent to absent port.

>>> import urllib.parse
>>> p = urllib.parse.urlparse('http://python.org:')
>>> p.hostname
'python.org'
>>> p.port  # should return None
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/serhiy/py/cpython-3.3/Lib/urllib/parse.py", line 156, in port
    port = int(port, 10)
ValueError: invalid literal for int() with base 10: ''
>>> urllib.parse.splitport('python.org:')  # should return ('python.org', None)
('python.org:', None)
>>> urllib.parse.splitnport('python.org:')  # should return ('python.org', -1)
('python.org', None)
>>> urllib.parse.splitnport('python.org:', 80)  # should return ('python.org', 80)
('python.org', None)

Proposed patch fixes this. It also adds tests for urllib.parse.splitport().
msg208404 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-01-18 16:32
New changeset a4a51a0d4575 by Serhiy Storchaka in branch '2.7':
Issue #20270: urllib and urlparse now support empty ports.
http://hg.python.org/cpython/rev/a4a51a0d4575

New changeset 52edc7087c81 by Serhiy Storchaka in branch '3.3':
Issue #20270: urllib.urlparse now supports empty ports.
http://hg.python.org/cpython/rev/52edc7087c81

New changeset 1469c4fde8cd by Serhiy Storchaka in branch 'default':
Issue #20270: urllib.urlparse now supports empty ports.
http://hg.python.org/cpython/rev/1469c4fde8cd
History
Date User Action Args
2022-04-11 14:57:57adminsetgithub: 64469
2014-01-18 16:33:04serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2014-01-18 16:32:10python-devsetnosy: + python-dev
messages: + msg208404
2014-01-15 12:37:09serhiy.storchakalinkissue18191 dependencies
2014-01-15 12:32:51serhiy.storchakalinkissue20271 dependencies
2014-01-15 12:26:25serhiy.storchakacreate