This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: bug in splituser(host) in urllib
Type: Stage:
Components: Library (Lib) Versions: Python 2.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: jhylton Nosy List: csarva, jhylton, nnorwitz, rhettinger
Priority: normal Keywords:

Created on 2002-07-15 04:36 by csarva, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Messages (4)
msg11593 - (view) Author: Chetan Sarva (csarva) Date: 2002-07-15 04:36
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
msg11594 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2002-08-11 15:30
Logged In: YES 
user_id=33168

Jeremy, how should this be fixed?
msg11595 - (view) Author: Jeremy Hylton (jhylton) (Python triager) Date: 2002-08-13 15:42
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.

msg11596 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2002-08-18 20:14
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.
History
Date User Action Args
2022-04-10 16:05:30adminsetgithub: 36896
2002-07-15 04:36:27csarvacreate