From a75796c64d397d37f1d41ae3d7e6bdf119b340d9 Mon Sep 17 00:00:00 2001 From: Marius Hein Date: Fri, 6 Jun 2014 13:52:45 +0200 Subject: [PATCH] Ui/Sparklines: Remove img src before putting it into DOM SVG chart was fetched although we removed image tags from DOM. This happens when text is converted into browser DOM model to use with javascript. Small regex remove img source attribute to avoid using network bandwidth for unknown resources. fixes #6124 --- public/js/icinga/loader.js | 2 +- public/js/icinga/ui.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/public/js/icinga/loader.js b/public/js/icinga/loader.js index 3b92e5b2f..338629136 100644 --- a/public/js/icinga/loader.js +++ b/public/js/icinga/loader.js @@ -269,7 +269,7 @@ if (this.processRedirectHeader(req)) return; // div helps getting an XML tree - var $resp = $('
' + req.responseText + '
'); + var $resp = $('
' + icinga.ui.removeImageSourceFromSparklines(req.responseText) + '
'); var active = false; var rendered = false; var classes; diff --git a/public/js/icinga/ui.js b/public/js/icinga/ui.js index e76e2dba8..6902953ca 100644 --- a/public/js/icinga/ui.js +++ b/public/js/icinga/ui.js @@ -657,6 +657,22 @@ ); }, + /** + * Find all svg charts and removes src attributes for sparklines + * + * @param {string} text + * @returns {string} + */ + removeImageSourceFromSparklines: function(text) { + var match, sourceMatch; + var re = new RegExp(/(src=".+chart.php[^"]+")/g); + var reSource = new RegExp(/src="([^"]+)"/); + while ((match = re.exec(text))) { + text = text.replace(match[0], ''); + } + return text; + }, + initializeControls: function (parent) { var self = this;