afeld / jsonpanel

pretty JSON viewer jQuery plugin
https://afeld.github.io/jsonpanel/
12 stars 1 forks source link

HTML escaping #13

Open kikonen opened 6 years ago

kikonen commented 6 years ago

It seems proper HTML escaping is not done. For example "<" and ">" are not escaped properly. I had message like this "Blah blaa". And this "" is it becomes html tag (which of course renders as empty).

kikonen commented 6 years ago

It looks like I was able to fix this with following change

  Pair.prototype.getKeyMarkup = function(){
    var formattedKey = JSON.stringify(this.key);
    var $formatter = $("<div>");
    $formatter.text(formattedKey);

    return '<span class="key">' + $formatter.html() + '</span>';
  };
...
  Pair.prototype.getValInnerMarkup = function(){
    var formattedValue = JSON.stringify(this.val);
    var $formatter = $("<div>");
    $formatter.text(formattedValue);
    return $formatter.html();
  };