mirror of
https://github.com/django/django.git
synced 2025-07-04 09:49:12 +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:
parent
7225efba50
commit
5e9aead902
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user