Skip to content

Commit

Permalink
Fixes an encoding issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
BertrandBordage committed Jun 30, 2013
1 parent 99829f0 commit 5cb0eee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 2 additions & 6 deletions terms/middleware.py
@@ -1,12 +1,8 @@
# coding: utf-8

from django.core.urlresolvers import resolve, Resolver404
try:
from django.utils.encoding import smart_text
except ImportError: # For Django < 1.4.2
from django.utils.encoding import smart_unicode as smart_text
from .html import replace_in_html
from .settings import TERMS_IGNORED_APPS, TERMS_DEBUG
from .templatetags.terms import replace_terms


class TermsMiddleware(object):
Expand All @@ -24,6 +20,6 @@ def process_response(self, request, response):
is_html = 'text/html' in response['Content-Type']

if not app_ignored and is_html and response.status_code == 200:
response.content = smart_text(replace_in_html(response.content))
response.content = replace_terms(response.content)

return response
10 changes: 10 additions & 0 deletions terms/tests/html/BeautifulSoup/valid_html.py
@@ -1,3 +1,6 @@
# coding: utf-8

from __future__ import unicode_literals
import os.path
from django.test import TestCase
from terms.templatetags.terms import replace_terms
Expand Down Expand Up @@ -25,3 +28,10 @@ def test(self):

new_html_w_extra_spaces = replace_terms(html_w_extra_spaces)
self.assertHTMLEqual(html, new_html_w_extra_spaces)

def testUnicode(self):
text = 'Il était une fois…'
self.assertEqual(text, replace_terms(text))

html = 'Il &eacute;tait une fois&hellip;'
self.assertEqual(text, replace_terms(html))

0 comments on commit 5cb0eee

Please sign in to comment.