Bug 13618: Add the escapeHtml JS prototype to String
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 9 Aug 2018 15:08:45 +0000 (12:08 -0300)
committerNick Clemens <nick@bywatersolutions.com>
Fri, 17 Aug 2018 15:55:11 +0000 (15:55 +0000)
Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
koha-tmpl/intranet-tmpl/prog/js/staff-global.js

index db5539a..fbbeed6 100644 (file)
@@ -15,6 +15,16 @@ function formatstr(str, col) {
     });
 }
 
+var HtmlCharsToEscape = {
+    '&': '&amp;',
+    '<': '&lt;',
+    '>': '&gt;'
+};
+String.prototype.escapeHtml = function() {
+    return this.replace(/[&<>]/g, function(c) {
+        return HtmlCharsToEscape[c] || c;
+    });
+};
 
 // http://stackoverflow.com/questions/14859281/select-tab-by-name-in-jquery-ui-1-10-0/16550804#16550804
 $.fn.tabIndex = function () {