[Python-bugs-list] [ python-Bugs-581529 ] bug in splituser(host) in urllib

noreply@sourceforge.net noreply@sourceforge.net
Sun, 18 Aug 2002 13:14:50 -0700


Bugs item #581529, was opened at 2002-07-14 23: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: Closed
>Resolution: Fixed
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: Raymond Hettinger (rhettinger)
Date: 2002-08-18 15:14

Message:
Logged In: YES 
user_id=80475

Based on Jeremy's response, Jonathan Simms submitted 
patch 596581 which is I tested and then applied as 
urllib.py 1.150 and 1.135.6.4

Closing bug and related patch.

Thank you to Chetan for the bug report.


----------------------------------------------------------------------

Comment By: Jeremy Hylton (jhylton)
Date: 2002-08-13 10: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 10: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