Django

Code

Changeset 5197

Show
Ignore:
Timestamp:
05/12/07 00:29:10 (1 year ago)
Author:
mtredinnick
Message:

unicode: Added handling for illegaly encoded form input.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/unicode/django/http/__init__.py

    r5184 r5197  
    361361def str_to_unicode(s, encoding): 
    362362    """ 
    363     Convert basestring objects to unicode, using the given encoding. 
     363    Convert basestring objects to unicode, using the given encoding. Illegaly 
     364    encoded input characters are replaced with Unicode "unknown" codepoint 
     365    (\ufffd). 
    364366 
    365367    Returns any non-basestring objects without change. 
    366368    """ 
    367369    if isinstance(s, str): 
    368         return unicode(s, encoding
     370        return unicode(s, encoding, 'replace'
    369371    else: 
    370372        return s 
  • django/branches/unicode/tests/regressiontests/httpwrappers/tests.py

    r5184 r5197  
    368368'vote=yes&vote=no' 
    369369 
     370# QueryDicts must be able to handle invalid input encoding (in this case, bad 
     371# UTF-8 encoding). 
     372>>> q = QueryDict('foo=bar&foo=\xff') 
     373 
     374>>> q['foo'] 
     375u'\ufffd' 
     376 
     377>>> q.getlist('foo') 
     378[u'bar', u'\ufffd'] 
     379 
    370380""" 
    371381