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: urllib2/urllib.parse.splitport does not handle IPv6 correctly
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.3, Python 3.4, Python 2.7
process
Status: open Resolution:
Dependencies: 20270 20271 Superseder:
Assigned To: Nosy List: berker.peksag, doughellmann, jd, samwyse, serhiy.storchaka, vstinner
Priority: normal Keywords: patch

Created on 2013-06-11 14:44 by jd, last changed 2022-04-11 14:57 by admin.

Files
File name Uploaded Description Edit
0001-Make-urllib.parse.splitport-handle-IPv6-correctly.patch jd, 2013-06-12 13:34 Patch fixing urllib.parse.splitport review
test_urlparse.diff samwyse, 2013-07-22 16:54 Revised test for urlparse
urllib.diff samwyse, 2013-07-22 16:56 Revised urllib
Messages (9)
msg190968 - (view) Author: Julien Danjou (jd) * Date: 2013-06-11 14:44
>>> import urllib.parse
>>> urllib.parse.splitport("::1")
(':', '1')

This is obviously invalid.
msg191027 - (view) Author: Julien Danjou (jd) * Date: 2013-06-12 13:34
Attached is a patch inspired by a function written for OpenStack Oslo library.
msg191040 - (view) Author: Doug Hellmann (doughellmann) * (Python committer) Date: 2013-06-12 17:43
LGTM
msg191041 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-06-12 18:40
I see only tests.

It is more common to use arguments for assertEqual() in the reverse order, first actual value, and than expected value.
msg191042 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2013-06-12 19:09
FTR, urllib.parse.splitport is undocumented and it is only used by urllib.request in the stdlib.
msg193546 - (view) Author: Samwyse (samwyse) * Date: 2013-07-22 16:54
Fixes Serhiy Storchaka's complaints, removes duplicate test.
msg193548 - (view) Author: Samwyse (samwyse) * Date: 2013-07-22 16:56
Handles "raw" IPv6 URLs
msg208157 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-01-15 12:37
Julien's patch is subject to bugs described in issue20270 and issue20271. As far as OpenStack Oslo library.
msg212891 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-03-07 16:23
I posted a patch to #20271 which should fix the issue. I wrote the patch for Python 3.5, but it can be adapted to be tolerant (don't make extensive tests on port number, host and IPv6) for older versions.
History
Date User Action Args
2022-04-11 14:57:46adminsetgithub: 62391
2014-03-07 16:23:13vstinnersetmessages: + msg212891
2014-01-15 12:37:09serhiy.storchakasettype: behavior
dependencies: + urllib.parse doesn't work with empty port, urllib.parse.urlparse() accepts wrong URLs
messages: + msg208157
versions: + Python 3.4, - Python 2.6
2013-10-17 16:34:13vstinnersetnosy: + vstinner
2013-07-22 16:56:04samwysesetfiles: + urllib.diff

messages: + msg193548
2013-07-22 16:54:44samwysesetfiles: + test_urlparse.diff
nosy: + samwyse
messages: + msg193546

2013-06-12 19:09:24berker.peksagsetnosy: + berker.peksag

messages: + msg191042
versions: - Python 3.1, Python 3.2
2013-06-12 18:40:12serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg191041
2013-06-12 17:43:51doughellmannsetmessages: + msg191040
2013-06-12 17:23:33doughellmannsetnosy: + doughellmann
2013-06-12 13:34:02jdsetfiles: + 0001-Make-urllib.parse.splitport-handle-IPv6-correctly.patch
keywords: + patch
messages: + msg191027
2013-06-11 14:44:39jdcreate