summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMattBlack85 <promat85@gmail.com>2014-02-15 18:55:33 +0100
committerBaptiste Mispelon <bmispelon@gmail.com>2014-02-15 19:39:21 +0100
commit1c1dffca757b0b6acaf99d893d68847250ab4146 (patch)
treeb4e1eaf22943204ecc2f3e1fd8d9b80e0df796ce
parent44814e78ccd3a54da41c1b77ba3504c648ef4e89 (diff)
Fixed #21725 -- Fixed JavaScript quoting encoding.
Thanks to nedbatchelder for the report.
-rw-r--r--django/utils/text.py2
-rw-r--r--tests/utils_tests/test_text.py5
2 files changed, 6 insertions, 1 deletions
diff --git a/django/utils/text.py b/django/utils/text.py
index d277cee56b..9e0afad47b 100644
--- a/django/utils/text.py
+++ b/django/utils/text.py
@@ -343,7 +343,7 @@ def javascript_quote(s, quote_double_quotes=False):
s = s.replace('</', '<\\/')
if quote_double_quotes:
s = s.replace('"', '&quot;')
- return str(ustring_re.sub(fix, s))
+ return ustring_re.sub(fix, s)
javascript_quote = allow_lazy(javascript_quote, six.text_type)
# Expression to match some_token and some_token="with spaces" (and similarly
diff --git a/tests/utils_tests/test_text.py b/tests/utils_tests/test_text.py
index bf547b62d2..4911cac908 100644
--- a/tests/utils_tests/test_text.py
+++ b/tests/utils_tests/test_text.py
@@ -155,3 +155,8 @@ class TestUtilsText(SimpleTestCase):
self.assertEqual(text.javascript_quote(input), '"Text"')
self.assertEqual(text.javascript_quote(input, quote_double_quotes=True),
'&quot;Text&quot;')
+
+ def test_javascript_quote_unicode(self):
+ input = "<script>alert('Hello \\xff.\n Wel𝕃come\there\r');</script>"
+ output = r"<script>alert(\'Hello \\xff.\n Wel𝕃come\there\r\');<\/script>"
+ self.assertEqual(text.javascript_quote(input), output)