You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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=Noneclosed_at=<Date2016-05-23.09:30:40.851>created_at=<Date2016-05-23.08:06:30.372>labels= ['invalid', 'type-bug', 'library']
title='I think this is a small bug in urlparse.py'updated_at=<Date2016-05-23.09:30:40.849>user='https://bugs.python.org/FengA'
netloc, url = _splitnetloc(url, 2)
if (('[' in netloc and ']' not in netloc) or
(']' in netloc and '[' not in netloc)):
raise ValueError("Invalid IPv6 URL")
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.
Activity
FengA commentedon May 23, 2016
=====================================================
BUG:
run : urlparse.urlparse('http://google.com]')
then: raise ValueError("Invalid IPv6 URL")
=====================================================
SOURCE:
=====================================================
SOLUTION:
I THINK IT IS BETTER TO JUST REMOVE THE LAST 3 LINES ABOVE
zhangyangyu commentedon May 23, 2016
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.
FengA commentedon May 23, 2016
I wish you could think twice if you hadn't use urlparse.py in practical project.
Do you like the module to raise an exception?
The href in webpage is always standard format?
Should the parse module verify the ipv6 url format? If so, did the module really make it?
Personally, Given a wrong formated url, It is the responsibility of the module to correct it ?
zhangyangyu commentedon May 23, 2016
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.
zhangyangyu commentedon May 23, 2016
Ohh, not objective, but subjective. Sorry.
ztane commentedon May 23, 2016
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.
berkerpeksag commentedon May 23, 2016
It's not the responsibility of the library to correct (or make a guess on) user input.