From 926e18d7d126fcf7f4b2d25ce4155423ac6e2f90 Mon Sep 17 00:00:00 2001 From: Baptiste Mispelon Date: Fri, 21 Feb 2014 14:46:23 +0100 Subject: [PATCH] Deprecated django.utils.text.javascript_quote. Refs #21725. --- django/utils/text.py | 6 ++++++ docs/internals/deprecation.txt | 2 ++ docs/releases/1.7.txt | 12 ++++++++++++ tests/utils_tests/test_text.py | 23 +++++++++++++++++------ tests/view_tests/tests/test_i18n.py | 14 +++++++------- 5 files changed, 44 insertions(+), 13 deletions(-) diff --git a/django/utils/text.py b/django/utils/text.py index 9e0afad47b5..1eee68bb177 100644 --- a/django/utils/text.py +++ b/django/utils/text.py @@ -4,6 +4,7 @@ import re import unicodedata from gzip import GzipFile from io import BytesIO +import warnings from django.utils.encoding import force_text from django.utils.functional import allow_lazy, SimpleLazyObject @@ -327,6 +328,11 @@ ustring_re = re.compile("([\u0080-\uffff])") def javascript_quote(s, quote_double_quotes=False): + msg = ( + "django.utils.text.javascript_quote() is deprecated. " + "Use django.utils.html.escapejs() instead." + ) + warnings.warn(msg, PendingDeprecationWarning, stacklevel=2) def fix(match): return "\\u%04x" % ord(match.group(1)) diff --git a/docs/internals/deprecation.txt b/docs/internals/deprecation.txt index 057c6dd3fe0..fdae4ea540e 100644 --- a/docs/internals/deprecation.txt +++ b/docs/internals/deprecation.txt @@ -119,6 +119,8 @@ details on these changes. * ``ssi`` and ``url`` template tags will be removed from the ``future`` template tag library (used during the 1.3/1.4 deprecation period). +* ``django.utils.text.javascript_quote`` will be removed. + .. _deprecation-removed-in-1.8: 1.8 diff --git a/docs/releases/1.7.txt b/docs/releases/1.7.txt index fc1f0f81cd6..e3144f3d292 100644 --- a/docs/releases/1.7.txt +++ b/docs/releases/1.7.txt @@ -1374,3 +1374,15 @@ Django 1.3 introduced ``{% load ssi from future %}`` and :ttag:`ssi` and :ttag:`url` template tags. This syntax is now deprecated and will be removed in Django 1.9. You can simply remove the ``{% load ... from future %}`` tags. + +``django.utils.text.javascript_quote`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +``javascript_quote()`` was an undocumented function present in ``django.utils.text``. +It was used internally in the :ref:`javascript_catalog view ` +whose implementation was changed to make use of ``json.dumps()`` instead. +If you were relying on this function to provide safe output from untrusted +strings, you should use ``django.utils.html.escapejs`` or the +:tfilter:`escapejs` template filter. +If all you need is to generate valid javascript strings, you can simply use +``json.dumps()``. diff --git a/tests/utils_tests/test_text.py b/tests/utils_tests/test_text.py index 12e441b81a6..8bfd4c6ca19 100644 --- a/tests/utils_tests/test_text.py +++ b/tests/utils_tests/test_text.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals from unittest import skipUnless +import warnings from django.test import SimpleTestCase from django.utils import six, text @@ -152,16 +153,26 @@ class TestUtilsText(SimpleTestCase): def test_javascript_quote(self): input = "" output = r"" output = r"