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: urllib's splitpasswd does not accept newline chars in passwords
Type: behavior Stage: test needed
Components: Library (Lib) Versions: Python 3.0, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: orsenthil Nosy List: ajaksu2, jhylton, mibanescu, orsenthil
Priority: normal Keywords: patch

Created on 2008-12-16 19:27 by mibanescu, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
splitpasswd.patch mibanescu, 2008-12-17 00:17 Patch and simple test cases
issue4675-py27.patch orsenthil, 2009-03-30 19:11
issue4675-py3k.patch orsenthil, 2009-03-30 19:11
Messages (5)
msg77919 - (view) Author: Mihai Ibanescu (mibanescu) Date: 2008-12-16 19:27
According to http://www.ietf.org/rfc/rfc2617.txt section 2, in basic
HTTP authentication the password can be any character (including newline).

urllib does the following:

_passwdprog = re.compile('^([^:]*):(.*)$')

That should be changed to:

_passwdprog = re.compile('^([^:]*):(.*)$', re.S)

otherwise newlines will not be caught by the second part of the regex,
and bad things are produced.

For a password with regular chars in it:

> python -c "import urllib; print urllib.splitpasswd('user:ab')"
('user', 'ab')

For a password with a newline:
> python -c "import urllib; print urllib.splitpasswd('user:a\nb')"
('user:a\nb', None)

The expected result should have been ('user', 'a\nb')
msg81801 - (view) Author: Daniel Diniz (ajaksu2) * (Python triager) Date: 2009-02-12 18:48
Inline test included in the patch.
msg84618 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2009-03-30 19:11
Verified the patch. Added unittest.
Can be applied against the trunk (py27) and py3k (3.1)
msg84662 - (view) Author: Jeremy Hylton (jhylton) (Python triager) Date: 2009-03-30 21:42
looks good to me
msg84670 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2009-03-30 21:58
Fixed.
History
Date User Action Args
2022-04-11 14:56:42adminsetgithub: 48925
2009-03-30 21:58:42orsenthilsetstatus: open -> closed
assignee: orsenthil
resolution: fixed
messages: + msg84670
2009-03-30 21:42:58jhyltonsetnosy: + jhylton
messages: + msg84662
2009-03-30 19:11:35orsenthilsetfiles: + issue4675-py3k.patch
2009-03-30 19:11:14orsenthilsetfiles: + issue4675-py27.patch

messages: + msg84618
2009-02-12 18:48:24ajaksu2setnosy: + ajaksu2, orsenthil
messages: + msg81801
stage: test needed
2008-12-17 00:17:55mibanescusetfiles: + splitpasswd.patch
keywords: + patch
2008-12-16 19:27:11mibanescucreate