summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2014-03-21 08:32:01 -0400
committerTim Graham <timograham@gmail.com>2014-03-21 08:50:43 -0400
commit8b81dee60c1533e714a310fa5c3907356042a64c (patch)
tree1c8d78cae84d3e502d284b8117d61f3737386177
parent99339c77f648fcdc30f6d914cb7efd902327ade7 (diff)
Removed fix_ampersands template filter per deprecation timeline.
Also removed related utility functions: * django.utils.html.fix_ampersands * django.utils.html.clean_html
-rw-r--r--django/template/defaultfilters.py8
-rw-r--r--django/utils/html.py49
-rw-r--r--docs/ref/templates/builtins.txt29
-rw-r--r--tests/defaultfilters/tests.py10
-rw-r--r--tests/template_tests/filters.py5
-rw-r--r--tests/template_tests/tests.py5
-rw-r--r--tests/utils_tests/test_html.py41
7 files changed, 3 insertions, 144 deletions
diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py
index 64f8e28190..f55aa072b7 100644
--- a/django/template/defaultfilters.py
+++ b/django/template/defaultfilters.py
@@ -12,7 +12,7 @@ from django.conf import settings
from django.utils import formats
from django.utils.dateformat import format, time_format
from django.utils.encoding import force_text, iri_to_uri
-from django.utils.html import (conditional_escape, escapejs, fix_ampersands,
+from django.utils.html import (conditional_escape, escapejs,
escape, urlize as _urlize, linebreaks, strip_tags, avoid_wrapping,
remove_tags)
from django.utils.http import urlquote
@@ -82,12 +82,6 @@ def escapejs_filter(value):
return escapejs(value)
-@register.filter("fix_ampersands", is_safe=True)
-@stringfilter
-def fix_ampersands_filter(value):
- """Replaces ampersands with ``&amp;`` entities."""
- return fix_ampersands(value)
-
# Values for testing floatformat input against infinity and NaN representations,
# which differ across platforms and Python versions. Some (i.e. old Windows
# ones) are not recognized by Decimal but we want to return them unchanged vs.
diff --git a/django/utils/html.py b/django/utils/html.py
index 6afd6b62fa..b9444fc01f 100644
--- a/django/utils/html.py
+++ b/django/utils/html.py
@@ -3,9 +3,7 @@
from __future__ import unicode_literals
import re
-import warnings
-from django.utils.deprecation import RemovedInDjango18Warning
from django.utils.encoding import force_text, force_str
from django.utils.functional import allow_lazy
from django.utils.safestring import SafeData, mark_safe
@@ -174,15 +172,6 @@ def strip_entities(value):
strip_entities = allow_lazy(strip_entities, six.text_type)
-def fix_ampersands(value):
- """Returns the given HTML with all unencoded ampersands encoded correctly."""
- # As fix_ampersands is wrapped in allow_lazy, stacklevel 3 is more useful than 2.
- warnings.warn("The fix_ampersands function is deprecated and will be removed in Django 1.8.",
- RemovedInDjango18Warning, stacklevel=3)
- return unencoded_ampersands_re.sub('&amp;', force_text(value))
-fix_ampersands = allow_lazy(fix_ampersands, six.text_type)
-
-
def smart_urlquote(url):
"Quotes a URL if it isn't already quoted."
# Handle IDN before quoting.
@@ -283,44 +272,6 @@ def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False):
urlize = allow_lazy(urlize, six.text_type)
-def clean_html(text):
- """
- Clean the given HTML. Specifically, do the following:
- * Convert <b> and <i> to <strong> and <em>.
- * Encode all ampersands correctly.
- * Remove all "target" attributes from <a> tags.
- * Remove extraneous HTML, such as presentational tags that open and
- immediately close and <br clear="all">.
- * Convert hard-coded bullets into HTML unordered lists.
- * Remove stuff like "<p>&nbsp;&nbsp;</p>", but only if it's at the
- bottom of the text.
- """
- # As clean_html is wrapped in allow_lazy, stacklevel 3 is more useful than 2.
- warnings.warn("The clean_html function is deprecated and will be removed in Django 1.8.",
- RemovedInDjango18Warning, stacklevel=3)
- text = normalize_newlines(text)
- text = re.sub(r'<(/?)\s*b\s*>', '<\\1strong>', text)
- text = re.sub(r'<(/?)\s*i\s*>', '<\\1em>', text)
- text = fix_ampersands(text)
- # Remove all target="" attributes from <a> tags.
- text = link_target_attribute_re.sub('\\1', text)
- # Trim stupid HTML such as <br clear="all">.
- text = html_gunk_re.sub('', text)
- # Convert hard-coded bullets into HTML unordered lists.
-
- def replace_p_tags(match):
- s = match.group().replace('</p>', '</li>')
- for d in DOTS:
- s = s.replace('<p>%s' % d, '<li>')
- return '<ul>\n%s\n</ul>' % s
- text = hard_coded_bullets_re.sub(replace_p_tags, text)
- # Remove stuff like "<p>&nbsp;&nbsp;</p>", 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 ``&amp;`` entities.
-
-For example::
-
- {{ value|fix_ampersands }}
-
-If ``value`` is ``Tom & Jerry``, the output will be ``Tom &amp; Jerry``.
-
-However, ampersands used in named entities and numeric character references
-will not be replaced. For example, if ``value`` is ``Caf&eacute;``, the output
-will *not* be ``Caf&amp;eacute;`` but remain ``Caf&eacute;``. 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 &amp; Jill &amp; 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&gt;")}, "Fred> Fred&gt;"),
'filter-capfirst02': ("{{ a|capfirst }} {{ b|capfirst }}", {"a": "fred>", "b": mark_safe("fred&gt;")}, "Fred&gt; Fred&gt;"),
- # 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&amp;b a&amp;b"),
- 'filter-fix_ampersands02': ("{{ a|fix_ampersands }} {{ b|fix_ampersands }}", {"a": "a&b", "b": mark_safe("a&b")}, "a&amp;amp;b a&amp;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&#1;", "b", "&a;", "&amp; &x; ", "asdf")
- patterns = (
- ("%s", "%s"),
- ("&%s", "&amp;%s"),
- ("&%s&", "&amp;%s&amp;"),
- )
-
- 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 = (
- ("&#;", "&amp;#;"),
- ("&#875 ;", "&amp;#875 ;"),
- ("&#4abc;", "&amp;#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 &amp; I don\'t <a href="#" >target</a>'),
- ('<p>I kill whitespace</p><br clear="all"><p>&nbsp;</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 = (