X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=plugins%2Flegend.js;h=fb93b419203bc53cac85c4b9eb9490152d44881e;hb=f7f4a6c0ea5f31130ff639b53095609562dfd86f;hp=66408b627d97cec64cefba5b4495b5df893420be;hpb=ee60939f4e2238cbb64ebbe7acdc27195c149cfb;p=dygraphs.git diff --git a/plugins/legend.js b/plugins/legend.js index 66408b6..fb93b41 100644 --- a/plugins/legend.js +++ b/plugins/legend.js @@ -120,6 +120,10 @@ var calculateEmWidthInDiv = function(div) { return oneEmWidth; }; +var escapeHTML = function(str) { + return str.replace(/&/g, "&").replace(/"/g, """).replace(//g, ">"); +}; + legend.prototype.select = function(e) { var xValue = e.selectedX; var points = e.selectedPoints; @@ -208,7 +212,7 @@ generateLegendHTML = function(g, x, sel_points, oneEmWidth) { strokePattern = g.getOption("strokePattern", labels[i]); dash = generateLegendDashHTML(strokePattern, series.color, oneEmWidth); html += "" + - dash + " " + labels[i] + ""; + dash + " " + escapeHTML(labels[i]) + ""; } return html; } @@ -245,7 +249,7 @@ generateLegendHTML = function(g, x, sel_points, oneEmWidth) { // TODO(danvk): use a template string here and make it an attribute. html += "" + " " + - pt.name + ": " + yval + ""; + escapeHTML(pt.name) + ": " + yval + ""; } return html; };