mirror of
https://github.com/django/django.git
synced 2025-04-26 02:04:38 +00:00
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:
parent
1bddac37b6
commit
5212911b19
@ -1,6 +1,7 @@
|
|||||||
"HTML utilities suitable for global use."
|
"HTML utilities suitable for global use."
|
||||||
|
|
||||||
import re, string
|
import re, string
|
||||||
|
from django.utils.encoding import smart_unicode
|
||||||
|
|
||||||
# Configuration for urlize() function
|
# Configuration for urlize() function
|
||||||
LEADING_PUNCTUATION = ['(', '<', '<']
|
LEADING_PUNCTUATION = ['(', '<', '<']
|
||||||
@ -24,7 +25,7 @@ del x # Temporary variable
|
|||||||
def escape(html):
|
def escape(html):
|
||||||
"Returns the given HTML with ampersands, quotes and carets encoded"
|
"Returns the given HTML with ampersands, quotes and carets encoded"
|
||||||
if not isinstance(html, basestring):
|
if not isinstance(html, basestring):
|
||||||
html = str(html)
|
html = smart_unicode(html)
|
||||||
return html.replace('&', '&').replace('<', '<').replace('>', '>').replace('"', '"').replace("'", ''')
|
return html.replace('&', '&').replace('<', '<').replace('>', '>').replace('"', '"').replace("'", ''')
|
||||||
|
|
||||||
def linebreaks(value):
|
def linebreaks(value):
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
r"""
|
r"""
|
||||||
>>> floatformat(7.7)
|
>>> floatformat(7.7)
|
||||||
'7.7'
|
'7.7'
|
||||||
@ -166,6 +168,9 @@ u'\xcb'
|
|||||||
>>> escape('<some html & special characters > here')
|
>>> escape('<some html & special characters > here')
|
||||||
'<some html & special characters > here'
|
'<some html & special characters > here'
|
||||||
|
|
||||||
|
>>> escape(u'<some html & special characters > here ĐÅ€£')
|
||||||
|
u'<some html & special characters > here \xc4\x90\xc3\x85\xe2\x82\xac\xc2\xa3'
|
||||||
|
|
||||||
>>> linebreaks('line 1')
|
>>> linebreaks('line 1')
|
||||||
'<p>line 1</p>'
|
'<p>line 1</p>'
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user