From ccbf178a3351106e25422b898f09cdca60a1c6e5 Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Fri, 18 Oct 2013 18:08:17 +0200 Subject: Fix crash with objects having a non-ASCII repr in context. --- tests/templates/basic.html | 7 +++++++ tests/tests.py | 4 ++++ tests/urls.py | 1 + tests/views.py | 13 ++++++++++--- 4 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 tests/templates/basic.html (limited to 'tests') diff --git a/tests/templates/basic.html b/tests/templates/basic.html new file mode 100644 index 0000000..a0ce0d4 --- /dev/null +++ b/tests/templates/basic.html @@ -0,0 +1,7 @@ + + + {{ title }} + + + + diff --git a/tests/tests.py b/tests/tests.py index 5886c12..86622fc 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -192,6 +192,10 @@ class DebugToolbarIntegrationTestCase(TestCase): if not six.PY3: self.assertContains(response, 'là') + def test_object_with_non_ascii_repr_in_context(self): + response = self.client.get('/non_ascii_context/') + self.assertContains(response, 'nôt åscíì') + def test_xml_validation(self): response = self.client.get('/regular/XML/') ET.fromstring(response.content) # shouldn't raise ParseError diff --git a/tests/urls.py b/tests/urls.py index 2877e73..d9ecb8c 100644 --- a/tests/urls.py +++ b/tests/urls.py @@ -18,5 +18,6 @@ urlpatterns = patterns('tests.views', url(r'^resolving2/(?P.+)/(?P.+)/$', 'resolving_view'), url(r'^resolving3/(.+)/$', 'resolving_view', { 'arg2' : 'default' }), url(r'^regular/(?P.*)/$', 'regular_view'), + url(r'^non_ascii_context/$', 'non_ascii_context'), url(r'^execute_sql/$', 'execute_sql'), ) diff --git a/tests/views.py b/tests/views.py index 8b51706..5bafc97 100644 --- a/tests/views.py +++ b/tests/views.py @@ -4,6 +4,7 @@ from __future__ import unicode_literals from django.contrib.auth.models import User from django.http import HttpResponse +from django.shortcuts import render from django.utils import six @@ -12,9 +13,15 @@ def execute_sql(request): return HttpResponse() +def non_ascii_context(request): + class NonAsciiRepr(object): + def __repr__(self): + return 'nôt åscíì' if six.PY3 else 'nôt åscíì'.encode('utf-8') + return render(request, 'basic.html', {'title': NonAsciiRepr()}) + + def regular_view(request, title): - content = '<html><head><title>%s' % title - return HttpResponse(content) + return render(request, 'basic.html', {'title': title}) def resolving_view(request, arg1, arg2): @@ -26,4 +33,4 @@ def set_session(request): request.session['où'] = 'où' if not six.PY3: request.session['là'.encode('utf-8')] = 'là'.encode('utf-8') - return HttpResponse('') + return render(request, 'basic.html') -- cgit v1.2.3