diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2009-04-11 09:27:04 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2009-04-11 09:27:04 +0000 |
| commit | b6bd5ddc3357d99f22f5181f5daecb46512650ba (patch) | |
| tree | 7ea0fb22cce001cf2c2aa84be63ccb9393e3769c /django | |
| parent | c2a828c7ca645adcd1cf55761c203f3dc62bdc8c (diff) | |
[1.0.X] Fixed #10571 -- Ensured that unicode POST data is correctly encoded by the test client. Thanks to Rick Wagner for his help identifying and fixing this problem.
Merge of r10513 from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@10514 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/test/client.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/django/test/client.py b/django/test/client.py index b144fe2fdb..ad2b63a729 100644 --- a/django/test/client.py +++ b/django/test/client.py @@ -1,6 +1,7 @@ import urllib import sys import os +import re try: from cStringIO import StringIO except ImportError: @@ -21,7 +22,7 @@ from django.utils.itercompat import is_iterable BOUNDARY = 'BoUnDaRyStRiNg' MULTIPART_CONTENT = 'multipart/form-data; boundary=%s' % BOUNDARY - +CONTENT_TYPE_RE = re.compile('.*; charset=([\w\d-]+);?') class FakePayload(object): """ @@ -279,7 +280,13 @@ class Client(object): if content_type is MULTIPART_CONTENT: post_data = encode_multipart(BOUNDARY, data) else: - post_data = data + # Encode the content so that the byte representation is correct. + match = CONTENT_TYPE_RE.match(content_type) + if match: + charset = match.group(1) + else: + charset = settings.DEFAULT_CHARSET + post_data = smart_str(data, encoding=charset) r = { 'CONTENT_LENGTH': len(post_data), |
