mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-13 06:47:28 -08:00
Merge pull request #610 from prometheus/fix-html-escaping
HTML-escape label values in Rickshaw hover-detail.
This commit is contained in:
commit
ca94e09a23
|
@ -365,7 +365,7 @@ Prometheus.Graph.prototype.renderLabels = function(labels) {
|
||||||
var labelStrings = [];
|
var labelStrings = [];
|
||||||
for (label in labels) {
|
for (label in labels) {
|
||||||
if (label != "__name__") {
|
if (label != "__name__") {
|
||||||
labelStrings.push("<strong>" + label + "</strong>: " + labels[label]);
|
labelStrings.push("<strong>" + label + "</strong>: " + escapeHTML(labels[label]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return labels = "<div class=\"labels\">" + labelStrings.join("<br>") + "</div>";
|
return labels = "<div class=\"labels\">" + labelStrings.join("<br>") + "</div>";
|
||||||
|
|
|
@ -386,6 +386,21 @@ PromConsole.Graph.prototype._parseValue = function(value) {
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PromConsole.Graph.prototype._escapeHTML = function(string) {
|
||||||
|
var entityMap = {
|
||||||
|
"&": "&",
|
||||||
|
"<": "<",
|
||||||
|
">": ">",
|
||||||
|
'"': '"',
|
||||||
|
"'": ''',
|
||||||
|
"/": '/'
|
||||||
|
};
|
||||||
|
|
||||||
|
return string.replace(/[&<>"'\/]/g, function (s) {
|
||||||
|
return entityMap[s];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
PromConsole.Graph.prototype._render = function(data) {
|
PromConsole.Graph.prototype._render = function(data) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var palette = new Rickshaw.Color.Palette();
|
var palette = new Rickshaw.Color.Palette();
|
||||||
|
@ -412,7 +427,7 @@ PromConsole.Graph.prototype._render = function(data) {
|
||||||
series[seriesLen++] = {
|
series[seriesLen++] = {
|
||||||
data: data[e].value[i].values.map(function(s) {return {x: s[0], y: self._parseValue(s[1])} }),
|
data: data[e].value[i].values.map(function(s) {return {x: s[0], y: self._parseValue(s[1])} }),
|
||||||
color: palette.color(),
|
color: palette.color(),
|
||||||
name: nameFunc(data[e].value[i].metric),
|
name: self._escapeHTML(nameFunc(data[e].value[i].metric)),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -530,7 +545,7 @@ PromConsole.Graph.prototype.dispatch = function() {
|
||||||
this.graphTd.appendChild(loadingImg);
|
this.graphTd.appendChild(loadingImg);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Substitue the value of 'label' for [[ label ]].
|
// Substitute the value of 'label' for [[ label ]].
|
||||||
PromConsole._interpolateName = function(name, metric) {
|
PromConsole._interpolateName = function(name, metric) {
|
||||||
var re = /(.*?)\[\[\s*(\w+)+\s*\]\](.*?)/g;
|
var re = /(.*?)\[\[\s*(\w+)+\s*\]\](.*?)/g;
|
||||||
var result = '';
|
var result = '';
|
||||||
|
|
Loading…
Reference in a new issue