mirror of
https://github.com/django/django.git
synced 2025-10-24 06:06:09 +00:00
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.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10513 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -2,6 +2,7 @@ import urllib
|
||||
from urlparse import urlparse, urlunparse, urlsplit
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
try:
|
||||
from cStringIO import StringIO
|
||||
except ImportError:
|
||||
@@ -25,7 +26,7 @@ from django.test.utils import ContextList
|
||||
|
||||
BOUNDARY = 'BoUnDaRyStRiNg'
|
||||
MULTIPART_CONTENT = 'multipart/form-data; boundary=%s' % BOUNDARY
|
||||
|
||||
CONTENT_TYPE_RE = re.compile('.*; charset=([\w\d-]+);?')
|
||||
|
||||
class FakePayload(object):
|
||||
"""
|
||||
@@ -290,7 +291,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)
|
||||
|
||||
parsed = urlparse(path)
|
||||
r = {
|
||||
|
||||
Reference in New Issue
Block a user