Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #21725 -- Fixed JavaScript quoting encoding.

Thanks to nedbatchelder for the report.
  • Loading branch information...
commit 1c1dffca757b0b6acaf99d893d68847250ab4146 1 parent 44814e7
@MattBlack85 MattBlack85 authored bmispelon committed
Showing with 6 additions and 1 deletion.
  1. +1 −1  django/utils/text.py
  2. +5 −0 tests/utils_tests/test_text.py
View
2  django/utils/text.py
@@ -343,7 +343,7 @@ def fix(match):
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
View
5 tests/utils_tests/test_text.py
@@ -155,3 +155,8 @@ def test_javascript_quote(self):
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)
Please sign in to comment.
Something went wrong with that request. Please try again.