mirror of
https://github.com/django/django.git
synced 2025-10-24 22:26:08 +00:00
Removed fix_ampersands template filter per deprecation timeline.
Also removed related utility functions: * django.utils.html.fix_ampersands * django.utils.html.clean_html
This commit is contained in:
@@ -4,12 +4,11 @@ from __future__ import unicode_literals
|
||||
import datetime
|
||||
import decimal
|
||||
import unittest
|
||||
import warnings
|
||||
|
||||
from django.template.defaultfilters import (
|
||||
add, addslashes, capfirst, center, cut, date, default, default_if_none,
|
||||
dictsort, dictsortreversed, divisibleby, escape, escapejs_filter,
|
||||
filesizeformat, first, fix_ampersands_filter, floatformat, force_escape,
|
||||
filesizeformat, first, floatformat, force_escape,
|
||||
get_digit, iriencode, join, length, length_is, linebreaksbr,
|
||||
linebreaks_filter, linenumbers, ljust, lower, make_list,
|
||||
phone2numeric_filter, pluralize, removetags, rjust, slice_filter, slugify,
|
||||
@@ -20,7 +19,6 @@ from django.template.defaultfilters import (
|
||||
from django.test import TestCase
|
||||
from django.utils import six
|
||||
from django.utils import translation
|
||||
from django.utils.deprecation import RemovedInDjango18Warning
|
||||
from django.utils.encoding import python_2_unicode_compatible
|
||||
from django.utils.safestring import SafeData
|
||||
|
||||
@@ -125,12 +123,6 @@ class DefaultFiltersTests(TestCase):
|
||||
escapejs_filter('paragraph separator:\u2029and line separator:\u2028'),
|
||||
'paragraph separator:\\u2029and line separator:\\u2028')
|
||||
|
||||
def test_fix_ampersands(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango18Warning)
|
||||
self.assertEqual(fix_ampersands_filter('Jack & Jill & Jeroboam'),
|
||||
'Jack & Jill & Jeroboam')
|
||||
|
||||
def test_linenumbers(self):
|
||||
self.assertEqual(linenumbers('line 1\nline 2'),
|
||||
'1. line 1\n2. line 2')
|
||||
|
||||
@@ -104,11 +104,6 @@ def get_filter_tests():
|
||||
'filter-capfirst01': ("{% autoescape off %}{{ a|capfirst }} {{ b|capfirst }}{% endautoescape %}", {"a": "fred>", "b": mark_safe("fred>")}, "Fred> Fred>"),
|
||||
'filter-capfirst02': ("{{ a|capfirst }} {{ b|capfirst }}", {"a": "fred>", "b": mark_safe("fred>")}, "Fred> Fred>"),
|
||||
|
||||
# Note that applying fix_ampsersands in autoescape mode leads to
|
||||
# double escaping.
|
||||
'filter-fix_ampersands01': ("{% autoescape off %}{{ a|fix_ampersands }} {{ b|fix_ampersands }}{% endautoescape %}", {"a": "a&b", "b": mark_safe("a&b")}, "a&b a&b"),
|
||||
'filter-fix_ampersands02': ("{{ a|fix_ampersands }} {{ b|fix_ampersands }}", {"a": "a&b", "b": mark_safe("a&b")}, "a&b a&b"),
|
||||
|
||||
'filter-floatformat01': ("{% autoescape off %}{{ a|floatformat }} {{ b|floatformat }}{% endautoescape %}", {"a": "1.42", "b": mark_safe("1.42")}, "1.4 1.4"),
|
||||
'filter-floatformat02': ("{{ a|floatformat }} {{ b|floatformat }}", {"a": "1.42", "b": mark_safe("1.42")}, "1.4 1.4"),
|
||||
|
||||
|
||||
@@ -602,10 +602,7 @@ class TemplateTests(TestCase):
|
||||
failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Template loading invoked method that shouldn't have been invoked." % (is_cached, invalid_str, template_debug, name))
|
||||
|
||||
try:
|
||||
with warnings.catch_warnings():
|
||||
# Ignore deprecation of fix_ampersands
|
||||
warnings.filterwarnings("ignore", category=DeprecationWarning, module='django.template.defaultfilters')
|
||||
output = self.render(test_template, vals)
|
||||
output = self.render(test_template, vals)
|
||||
except ShouldNotExecuteException:
|
||||
failures.append("Template test (Cached='%s', TEMPLATE_STRING_IF_INVALID='%s', TEMPLATE_DEBUG=%s): %s -- FAILED. Template rendering invoked method that shouldn't have been invoked." % (is_cached, invalid_str, template_debug, name))
|
||||
except ContextStackException:
|
||||
|
||||
@@ -4,11 +4,9 @@ from __future__ import unicode_literals
|
||||
from datetime import datetime
|
||||
import os
|
||||
from unittest import TestCase
|
||||
import warnings
|
||||
|
||||
from django.utils import html, safestring
|
||||
from django.utils._os import upath
|
||||
from django.utils.deprecation import RemovedInDjango18Warning
|
||||
from django.utils.encoding import force_text
|
||||
|
||||
|
||||
@@ -131,31 +129,6 @@ class TestUtilsHtml(TestCase):
|
||||
for in_pattern, output in patterns:
|
||||
self.check_output(f, in_pattern % {'entity': entity}, output)
|
||||
|
||||
def test_fix_ampersands(self):
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango18Warning)
|
||||
f = html.fix_ampersands
|
||||
# Strings without ampersands or with ampersands already encoded.
|
||||
values = ("a", "b", "&a;", "& &x; ", "asdf")
|
||||
patterns = (
|
||||
("%s", "%s"),
|
||||
("&%s", "&%s"),
|
||||
("&%s&", "&%s&"),
|
||||
)
|
||||
|
||||
for value in values:
|
||||
for in_pattern, out_pattern in patterns:
|
||||
self.check_output(f, in_pattern % value, out_pattern % value)
|
||||
|
||||
# Strings with ampersands that need encoding.
|
||||
items = (
|
||||
("&#;", "&#;"),
|
||||
("ͫ ;", "&#875 ;"),
|
||||
("abc;", "&#4abc;"),
|
||||
)
|
||||
for value, output in items:
|
||||
self.check_output(f, value, output)
|
||||
|
||||
def test_escapejs(self):
|
||||
f = html.escapejs
|
||||
items = (
|
||||
@@ -168,20 +141,6 @@ class TestUtilsHtml(TestCase):
|
||||
for value, output in items:
|
||||
self.check_output(f, value, output)
|
||||
|
||||
def test_clean_html(self):
|
||||
f = html.clean_html
|
||||
items = (
|
||||
('<p>I <i>believe</i> in <b>semantic markup</b>!</p>', '<p>I <em>believe</em> in <strong>semantic markup</strong>!</p>'),
|
||||
('I escape & I don\'t <a href="#" target="_blank">target</a>', 'I escape & I don\'t <a href="#" >target</a>'),
|
||||
('<p>I kill whitespace</p><br clear="all"><p> </p>', '<p>I kill whitespace</p>'),
|
||||
# also a regression test for #7267: this used to raise an UnicodeDecodeError
|
||||
('<p>* foo</p><p>* bar</p>', '<ul>\n<li> foo</li><li> bar</li>\n</ul>'),
|
||||
)
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore", RemovedInDjango18Warning)
|
||||
for value, output in items:
|
||||
self.check_output(f, value, output)
|
||||
|
||||
def test_remove_tags(self):
|
||||
f = html.remove_tags
|
||||
items = (
|
||||
|
||||
Reference in New Issue
Block a user