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.

Title: I think this is a small bug in
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.4, Python 2.7
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Feng A, berker.peksag, xiang.zhang, ztane
Priority: normal Keywords:

Created on 2016-05-23 08:06 by Feng A, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (7)
msg266125 - (view) Author: Feng A (Feng A) Date: 2016-05-23 08:06

run : urlparse.urlparse(']')
then: raise ValueError("Invalid IPv6 URL")


    if url[:2] == '//':

        netloc, url = _splitnetloc(url, 2)

        if (('[' in netloc and ']' not in netloc) or

                (']' in netloc and '[' not in netloc)):

            raise ValueError("Invalid IPv6 URL")


msg266126 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2016-05-23 08:17
Why? I think this is the right behaviour. According to the rfc[1], square brackets are used and only used to refer IPv6 address in URI. Square brackets are reserved characters and the URI you give is not correct.

msg266127 - (view) Author: Feng A (Feng A) Date: 2016-05-23 08:51
I wish you could think twice if you hadn't use in practical project.  

1. Do you like the module to raise an exception?
2. The href in webpage is always standard format?
3. Should the parse module verify the ipv6 url format? If so, did the module really make it?

4. Personally, Given a wrong formated url, It is the responsibility of the module to correct it ?
msg266128 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2016-05-23 09:03
As a general purpose library for url parsing, I think conforming to the existing standard is a good choice.

']' is a malformed URI according to the standard and then I think raising an exception is quite suitable. Of course there are always malformed links in webpages but how to correct them is quite objective. I think catch the exception in application and correct them in your own logic is what you should do.
msg266129 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2016-05-23 09:04
Ohh, not objective, but subjective. Sorry.
msg266130 - (view) Author: Antti Haapala (ztane) * Date: 2016-05-23 09:20
This behaviour exists exactly because the return value also contains the `.hostname`, which for the IPv6 addresses is *without* brackets:

    >>> urlparse('http://[::1]:80/').hostname

There is no way to get a proper parsing result from such a broken URI.
msg266131 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016-05-23 09:30
> 4. Personally, Given a wrong formated url, It is the responsibility of the module to correct it ?

It's not the responsibility of the library to correct (or make a guess on) user input.
Date User Action Args
2022-04-11 14:58:31adminsetgithub: 71276
2016-05-23 09:30:40berker.peksagsetstatus: open -> closed

nosy: + berker.peksag
messages: + msg266131

resolution: not a bug
stage: resolved
2016-05-23 09:20:01ztanesetnosy: + ztane
messages: + msg266130
2016-05-23 09:04:27xiang.zhangsetmessages: + msg266129
2016-05-23 09:03:35xiang.zhangsetmessages: + msg266128
2016-05-23 08:51:45Feng Asetmessages: + msg266127
2016-05-23 08:17:52xiang.zhangsetnosy: + xiang.zhang
messages: + msg266126
2016-05-23 08:06:30Feng Acreate