[Python-bugs-list] [ python-Bugs-581529 ] bug in splituser(host) in urllib
noreply@sourceforge.net
noreply@sourceforge.net
Tue, 13 Aug 2002 08:42:51 -0700
Bugs item #581529, was opened at 2002-07-15 04:36
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=581529&group_id=5470
Category: Python Library
Group: Python 2.2.1
Status: Open
Resolution: None
Priority: 5
Submitted By: Chetan Sarva (csarva)
Assigned to: Jeremy Hylton (jhylton)
Summary: bug in splituser(host) in urllib
Initial Comment:
The splituser() method splits on the very first "@" it encounters
which can lead to inaccurate results in certain cases (i.e. if the
username portion contains an e-mail address). Splitting on the last
"@" in the string will give the desired results every time.
I'm
not very good with regex's so I've given my simple solution as a
sample below:
_userprog = None
def
splituser(host):
"""splituser('user[:passwd]@host[:port]') -->
'user[:passwd]', 'host[:port]'."""
global _userprog
if
_userprog is None:
x = host.rfind('@')
if x != -1:
return
host[:x], host[x+1:]
else:
return None, host
#import re
#_userprog = re.compile('^([^@]*)@(.*)$')
#match = _userprog.match(host)
#if match: return
map(unquote, match.group(1, 2))
return None, host
----------------------------------------------------------------------
>Comment By: Jeremy Hylton (jhylton)
Date: 2002-08-13 15:42
Message:
Logged In: YES
user_id=31392
The '@' in the userinfo is not legal according to RFC 2396.
It must be escaped.
But I suppose other tools handle this without the escaping,
so we ought to also. '@' isn't legal in the host part
either, but it's much less likely to occur there.
----------------------------------------------------------------------
Comment By: Neal Norwitz (nnorwitz)
Date: 2002-08-11 15:30
Message:
Logged In: YES
user_id=33168
Jeremy, how should this be fixed?
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=581529&group_id=5470