summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaulo Matias <matias@ufscar.br>2016-09-01 15:57:34 -0300
committerPaulo Matias <matias@ufscar.br>2016-09-01 16:45:15 -0300
commit5627065ee60f76ac231a88e1609c18cd5b6e145f (patch)
tree968a6124bef3f9800a20272725ab11ea02553857
parentccd20a9dd2c192e1a1013c1d83d437ed12ddec21 (diff)
downloadhorizon-5627065ee60f76ac231a88e1609c18cd5b6e145f.tar.gz
Escape backslash in the angular_escapes filter
Follow-up for Ic97c6f3b0e3c4c91323dcba82bfe43e252e16b1a. Supersedes Icbf97fea50183702aaacbe3b9be0d44a5797df9a. Change-Id: Idb58cebefab747f204e54ea6350db0852aec60f5 Co-Authored-By: Matt Borland <matt.borland@hpe.com> Co-Authored-By: Tadeu Sampaio <tadeu@ufscar.br> Closes-Bug: #1617749
-rw-r--r--horizon/templatetags/angular.py1
-rw-r--r--horizon/test/tests/templatetags.py20
2 files changed, 21 insertions, 0 deletions
diff --git a/horizon/templatetags/angular.py b/horizon/templatetags/angular.py
index b01c8b1ce..b86e2bc7f 100644
--- a/horizon/templatetags/angular.py
+++ b/horizon/templatetags/angular.py
@@ -66,6 +66,7 @@ def angular_escapes(value):
string with escaped values
"""
return value \
+ .replace('\\', '\\\\') \
.replace('"', '\\"') \
.replace("'", "\\'") \
.replace("\n", "\\n") \
diff --git a/horizon/test/tests/templatetags.py b/horizon/test/tests/templatetags.py
index 899d98714..96533218c 100644
--- a/horizon/test/tests/templatetags.py
+++ b/horizon/test/tests/templatetags.py
@@ -112,6 +112,26 @@ class TemplateTagTests(test.TestCase):
context={'test': ctx_string})
self.assertEqual(expected, rendered_str)
+ def test_angular_escapes_filter(self):
+ ctx_string = {'val1': "\'a \"quotes\" test\'",
+ 'val2': "how about line\r\nbreaks",
+ 'val3': "\\s\\l\\a\\s\\h"}
+
+ text = ('{% autoescape off %}'
+ '<"{{ test.val1|angular_escapes }}",'
+ ' "{{ test.val2|angular_escapes }}",'
+ ' "{{ test.val3|angular_escapes }}">'
+ '{% endautoescape %}')
+
+ expected = (r""" <"\'a \"quotes\" test\'","""
+ r""" "how about line\r\nbreaks","""
+ r""" "\\s\\l\\a\\s\\h">""")
+
+ rendered_str = self.render_template(tag_require='angular',
+ template_text=text,
+ context={'test': ctx_string})
+ self.assertEqual(expected, rendered_str)
+
def test_horizon_main_nav(self):
text = "{% horizon_main_nav %}"
expected = """