Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1738)

Unified Diff: scripts/master/master_utils.py

Issue 2486943004: Adding escapejs filter for Jinja templates (Closed)
Patch Set: Adding escapejs filter for Jinja templates Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: scripts/master/master_utils.py
diff --git a/scripts/master/master_utils.py b/scripts/master/master_utils.py
index d9907482fe1e64b636d9f4725ff7c2e686a3aba3..c1f79d19dc123124277e8204f90df3093547ba79 100644
--- a/scripts/master/master_utils.py
+++ b/scripts/master/master_utils.py
@@ -252,12 +252,35 @@ class FilterDomain(util.ComparableMixin):
return None
return result
+# Based on django.utils.html.escapejs from the Django project
+def EscapeJs(t):
+ """Replaces javascript special characters in the supplied string.
+
+ Characters are replaced with a textual representation of their integer
+ ordinal."""
+ js_escapes = {
+ '\\': '\\u005C',
+ '\'': '\\u0027',
+ '"': '\\u0022',
+ '>': '\\u003E',
+ '<': '\\u003C',
+ '&': '\\u0026',
+ '=': '\\u003D',
+ '-': '\\u002D',
+ ';': '\\u003B',
+ u'\u2028': '\\u2028',
+ u'\u2029': '\\u2029',
+ }
+ for k, v in js_escapes.items():
+ t = t.replace(k, v)
+ return t
def CreateWebStatus(port, templates=None, tagComparator=None,
customEndpoints=None, console_repo_filter=None,
console_builder_filter=None, web_template_globals=None,
**kwargs):
webstatus = WebStatus(port, **kwargs)
+ webstatus.templates.filters.update({"escapejs": EscapeJs})
if templates:
# Manipulate the search path for jinja templates
# pylint: disable=F0401
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698