Skip to content

I think this is a small bug in urlparse.py #71276

Closed

Description

@FengA
mannequin
BPO 27089
Nosy @berkerpeksag, @ztane, @zhangyangyu

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2016-05-23.09:30:40.851>
created_at = <Date 2016-05-23.08:06:30.372>
labels = ['invalid', 'type-bug', 'library']
title = 'I think this is a small bug in urlparse.py'
updated_at = <Date 2016-05-23.09:30:40.849>
user = 'https://bugs.python.org/FengA'

bugs.python.org fields:

activity = <Date 2016-05-23.09:30:40.849>
actor = 'berker.peksag'
assignee = 'none'
closed = True
closed_date = <Date 2016-05-23.09:30:40.851>
closer = 'berker.peksag'
components = ['Library (Lib)']
creation = <Date 2016-05-23.08:06:30.372>
creator = 'Feng A'
dependencies = []
files = []
hgrepos = []
issue_num = 27089
keywords = []
message_count = 7.0
messages = ['266125', '266126', '266127', '266128', '266129', '266130', '266131']
nosy_count = 4.0
nosy_names = ['berker.peksag', 'ztane', 'xiang.zhang', 'Feng A']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue27089'
versions = ['Python 2.7', 'Python 3.4']

Activity

  1. FengA commented on May 23, 2016

    FengAmannequin
    MannequinAuthor

    =====================================================
    BUG:

    run : urlparse.urlparse('http://google.com]')
    then: raise ValueError("Invalid IPv6 URL")

    =====================================================
    SOURCE:

        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")
    

    =====================================================
    SOLUTION:

    I THINK IT IS BETTER TO JUST REMOVE THE LAST 3 LINES ABOVE

  2. added
    stdlib
    type-bug
    on May 23, 2016
  3. zhangyangyu commented on May 23, 2016

    @zhangyangyu
    Member

    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.

    1. http://tools.ietf.org/html/rfc3986#section-3
  4. FengA commented on May 23, 2016

    FengAmannequin
    MannequinAuthor

    I wish you could think twice if you hadn't use urlparse.py 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 ?

  5. zhangyangyu commented on May 23, 2016

    @zhangyangyu
    Member

    As a general purpose library for url parsing, I think conforming to the existing standard is a good choice.

    'http://google.com]' 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.

  6. zhangyangyu commented on May 23, 2016

    @zhangyangyu
    Member

    Ohh, not objective, but subjective. Sorry.

  7. ztane commented on May 23, 2016

    ztanemannequin
    Mannequin

    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
        '::1'

    There is no way to get a proper parsing result from such a broken URI.

  8. berkerpeksag commented on May 23, 2016

    @berkerpeksag
    Member
    1. 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.

  9. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibtype-bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions