1
0
mirror of https://github.com/django/django.git synced 2025-07-04 01:39:20 +00:00

unicode: Added handling for illegaly encoded form input.

git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5197 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2007-05-12 05:29:10 +00:00
parent 7225efba50
commit 5e9aead902
2 changed files with 14 additions and 2 deletions

View File

@ -360,12 +360,14 @@ def get_host(request):
# this slightly more restricted function.
def str_to_unicode(s, encoding):
"""
Convert basestring objects to unicode, using the given encoding.
Convert basestring objects to unicode, using the given encoding. Illegaly
encoded input characters are replaced with Unicode "unknown" codepoint
(\ufffd).
Returns any non-basestring objects without change.
"""
if isinstance(s, str):
return unicode(s, encoding)
return unicode(s, encoding, 'replace')
else:
return s

View File

@ -367,6 +367,16 @@ AttributeError: This QueryDict instance is immutable
>>> q.urlencode()
'vote=yes&vote=no'
# QueryDicts must be able to handle invalid input encoding (in this case, bad
# UTF-8 encoding).
>>> q = QueryDict('foo=bar&foo=\xff')
>>> q['foo']
u'\ufffd'
>>> q.getlist('foo')
[u'bar', u'\ufffd']
"""
from django.http import QueryDict