Fixed #21731 -- Made javascript_quote escapes '</'.
This commit is contained in:
parent
b17c75564f
commit
c43c469a2e
|
@ -327,6 +327,7 @@ def javascript_quote(s, quote_double_quotes=False):
|
|||
s = s.replace('\n', '\\n')
|
||||
s = s.replace('\t', '\\t')
|
||||
s = s.replace("'", "\\'")
|
||||
s = s.replace('</', '<\\/')
|
||||
if quote_double_quotes:
|
||||
s = s.replace('"', '"')
|
||||
return str(ustring_re.sub(fix, s))
|
||||
|
|
|
@ -144,3 +144,14 @@ class TestUtilsText(SimpleTestCase):
|
|||
def test_get_valid_filename(self):
|
||||
filename = "^&'@{}[],$=!-#()%+~_123.txt"
|
||||
self.assertEqual(text.get_valid_filename(filename), "-_123.txt")
|
||||
|
||||
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)
|
||||
|
||||
# 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"')
|
||||
|
|
Loading…
Reference in New Issue