Made django.utils.html.escape() work with unicode strings (and unicode-like

objects). Refs #3897.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@4919 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick 2007-04-04 06:43:28 +00:00
parent 1bddac37b6
commit 5212911b19
2 changed files with 14 additions and 8 deletions

View file

@ -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 = ['(', '<', '&lt;']
@ -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('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;').replace('"', '&quot;').replace("'", '&#39;')
def linebreaks(value):