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

noreply@sourceforge.net noreply@sourceforge.net
Sun, 14 Jul 2002 21:36:27 -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: Open
Resolution: None
Priority: 5
Submitted By: Chetan Sarva (csarva)
Assigned to: Nobody/Anonymous (nobody)
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

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

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=581529&group_id=5470