diff --git a/django/utils/html.py b/django/utils/html.py index baa2fb06fc..d06440b52e 100644 --- a/django/utils/html.py +++ b/django/utils/html.py @@ -1,6 +1,7 @@ "HTML utilities suitable for global use." import re, string +from django.utils.encoding import smart_unicode # Configuration for urlize() function LEADING_PUNCTUATION = ['(', '<', '<'] @@ -24,7 +25,7 @@ del x # Temporary variable def escape(html): "Returns the given HTML with ampersands, quotes and carets encoded" if not isinstance(html, basestring): - html = str(html) + html = smart_unicode(html) return html.replace('&', '&').replace('<', '<').replace('>', '>').replace('"', '"').replace("'", ''') def linebreaks(value): diff --git a/tests/regressiontests/defaultfilters/tests.py b/tests/regressiontests/defaultfilters/tests.py index db3f7fab2a..4a2e9432b0 100644 --- a/tests/regressiontests/defaultfilters/tests.py +++ b/tests/regressiontests/defaultfilters/tests.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + r""" >>> floatformat(7.7) '7.7' @@ -87,19 +89,19 @@ u'\xeb' >>> truncatewords('A sentence with a few words in it', 'not a number') 'A sentence with a few words in it' ->>> truncatewords_html('
one two - three
four five
one two - three
four five
one two - three
four five
one two - three
four five
one two ...
' - ->>> truncatewords_html('one two - three
four five
one two - three
four five
one two - three
four five
one two - three
four five
one two - three
four five
one two - three
four five
one two - three
four five
one two - three
four five
line 1
'