Escape < and > before styling the JSON
authorMarkus Lanthaler <mark_lanthaler@gmx.net>
Fri, 17 Aug 2012 18:15:37 +0200
changeset 814 88bb8d65b0cd
parent 813 fa532f0d901d
child 815 1f429de2871f
Escape < and > before styling the JSON

.. otherwise it is misinterpreted as HTML.
playground/playground.js
--- a/playground/playground.js	Fri Aug 17 18:12:55 2012 +0200
+++ b/playground/playground.js	Fri Aug 17 18:15:37 2012 +0200
@@ -215,7 +215,7 @@
         if(err) {
           return callback(err);
         }
-        $('#expanded').html(js_beautify(JSON.stringify(expanded),
+        $('#expanded').html(js_beautify(JSON.stringify(expanded).replace('<', '&lt;').replace('>', '&gt;'),
           {'indent_size': 2, 'brace_style': 'expand'}));
         callback();
       });
@@ -225,7 +225,7 @@
         if(err) {
           return callback(err);
         }
-        $('#compacted').html(js_beautify(JSON.stringify(compacted),
+        $('#compacted').html(js_beautify(JSON.stringify(compacted).replace('<', '&lt;').replace('>', '&gt;'),
           {'indent_size': 2, 'brace_style': 'expand'}));
         callback();
       });
@@ -235,7 +235,7 @@
         if(err) {
           return callback(err);
         }
-        $('#framed').html(js_beautify(JSON.stringify(framed),
+        $('#framed').html(js_beautify(JSON.stringify(framed).replace('<', '&lt;').replace('>', '&gt;'),
           {'indent_size': 2, 'brace_style': 'expand'}));
         callback();
       });