mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
parent
847171b0d0
commit
926e18d7d1
5 changed files with 44 additions and 13 deletions
|
@ -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 = "<script>alert('Hello \\xff.\n Welcome\there\r');</script>"
|
||||
output = r"<script>alert(\'Hello \\xff.\n Welcome\there\r\');<\/script>"
|
||||
self.assertEqual(text.javascript_quote(input), output)
|
||||
with warnings.catch_warnings():
|
||||
self.assertEqual(text.javascript_quote(input), output)
|
||||
|
||||
# Exercising quote_double_quotes keyword argument
|
||||
input = '"Text"'
|
||||
self.assertEqual(text.javascript_quote(input), '"Text"')
|
||||
self.assertEqual(text.javascript_quote(input, quote_double_quotes=True),
|
||||
'"Text"')
|
||||
with warnings.catch_warnings():
|
||||
self.assertEqual(text.javascript_quote(input), '"Text"')
|
||||
self.assertEqual(text.javascript_quote(input, quote_double_quotes=True),
|
||||
'"Text"')
|
||||
|
||||
@skipUnless(IS_WIDE_BUILD)
|
||||
@skipUnless(IS_WIDE_BUILD, 'Not running in a wide build of Python')
|
||||
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)
|
||||
with warnings.catch_warnings():
|
||||
self.assertEqual(text.javascript_quote(input), output)
|
||||
|
||||
def test_deprecation(self):
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter("always")
|
||||
text.javascript_quote('thingy')
|
||||
self.assertEqual(len(w), 1)
|
||||
self.assertIn('escapejs()', repr(w[0].message))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue