mirror of
https://github.com/django/django.git
synced 2025-10-26 07:06:08 +00:00
Fixed #2986 -- Made the JavaScript code that drives related model instance addition in a popup window handle a model representation containing new lines. Also, moved the escapejs functionality yoo django.utils.html so it can be used from Python code. Thanks andrewwatts for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15131 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -34,6 +34,31 @@ def escape(html):
|
||||
return mark_safe(force_unicode(html).replace('&', '&').replace('<', '<').replace('>', '>').replace('"', '"').replace("'", '''))
|
||||
escape = allow_lazy(escape, unicode)
|
||||
|
||||
_base_js_escapes = (
|
||||
('\\', r'\u005C'),
|
||||
('\'', r'\u0027'),
|
||||
('"', r'\u0022'),
|
||||
('>', r'\u003E'),
|
||||
('<', r'\u003C'),
|
||||
('&', r'\u0026'),
|
||||
('=', r'\u003D'),
|
||||
('-', r'\u002D'),
|
||||
(';', r'\u003B'),
|
||||
(u'\u2028', r'\u2028'),
|
||||
(u'\u2029', r'\u2029')
|
||||
)
|
||||
|
||||
# Escape every ASCII character with a value less than 32.
|
||||
_js_escapes = (_base_js_escapes +
|
||||
tuple([('%c' % z, '\\u%04X' % z) for z in range(32)]))
|
||||
|
||||
def escapejs(value):
|
||||
"""Hex encodes characters for use in JavaScript strings."""
|
||||
for bad, good in _js_escapes:
|
||||
value = mark_safe(force_unicode(value).replace(bad, good))
|
||||
return value
|
||||
escapejs = allow_lazy(escapejs, unicode)
|
||||
|
||||
def conditional_escape(html):
|
||||
"""
|
||||
Similar to escape(), except that it doesn't operate on pre-escaped strings.
|
||||
|
||||
Reference in New Issue
Block a user