From 8b81dee60c1533e714a310fa5c3907356042a64c Mon Sep 17 00:00:00 2001
From: Tim Graham
.
- * Convert hard-coded bullets into HTML unordered lists.
- * Remove stuff like "
.
- text = html_gunk_re.sub('', text)
- # Convert hard-coded bullets into HTML unordered lists.
-
- def replace_p_tags(match):
- s = match.group().replace('
%s' % d, '
", but only if it's at the bottom - # of the text. - text = trailing_empty_content_re.sub('', text) - return text -clean_html = allow_lazy(clean_html, six.text_type) - - def avoid_wrapping(value): """ Avoid text wrapping in the middle of a phrase by adding non-breaking diff --git a/docs/ref/templates/builtins.txt b/docs/ref/templates/builtins.txt index 7900e5ed70..4f8102c003 100644 --- a/docs/ref/templates/builtins.txt +++ b/docs/ref/templates/builtins.txt @@ -1572,35 +1572,6 @@ For example:: If ``value`` is the list ``['a', 'b', 'c']``, the output will be ``'a'``. -.. templatefilter:: fix_ampersands - -fix_ampersands -^^^^^^^^^^^^^^ - -.. note:: - - This is rarely useful as ampersands are automatically escaped. See - :tfilter:`escape` for more information. - -.. deprecated:: 1.7 - This filter has been deprecated and will be removed in Django 1.8. - -Replaces ampersands with ``&`` entities. - -For example:: - - {{ value|fix_ampersands }} - -If ``value`` is ``Tom & Jerry``, the output will be ``Tom & Jerry``. - -However, ampersands used in named entities and numeric character references -will not be replaced. For example, if ``value`` is ``Café``, the output -will *not* be ``Café`` but remain ``Café``. This means that -in some edge cases, such as acronyms followed by semicolons, this filter will -not replace ampersands that need replacing. For example, if ``value`` is -``Contact the R&D;``, the output will remain unchanged because ``&D;`` -resembles a named entity. - .. templatefilter:: floatformat floatformat diff --git a/tests/defaultfilters/tests.py b/tests/defaultfilters/tests.py index ee328f4e38..966e86bbaa 100644 --- a/tests/defaultfilters/tests.py +++ b/tests/defaultfilters/tests.py @@ -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') diff --git a/tests/template_tests/filters.py b/tests/template_tests/filters.py index ad85d0cb0b..371d0325b6 100644 --- a/tests/template_tests/filters.py +++ b/tests/template_tests/filters.py @@ -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"), diff --git a/tests/template_tests/tests.py b/tests/template_tests/tests.py index 784f59ecd9..0f060d9a2a 100644 --- a/tests/template_tests/tests.py +++ b/tests/template_tests/tests.py @@ -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: diff --git a/tests/utils_tests/test_html.py b/tests/utils_tests/test_html.py index 51ff38d190..b4e61b9fd6 100644 --- a/tests/utils_tests/test_html.py +++ b/tests/utils_tests/test_html.py @@ -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 = ( - ("", "&#;"), - ("ͫ ;", "ͫ ;"), - ("abc;", "abc;"), - ) - 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 = ( - ('
I believe in semantic markup!
', 'I believe in semantic markup!
'), - ('I escape & I don\'t target', 'I escape & I don\'t target'), - ('I kill whitespace
', '
I kill whitespace
'), - # also a regression test for #7267: this used to raise an UnicodeDecodeError - ('* foo
* bar
', '