Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

Fixed html entity escaping in doc reporter code

Tj Holowaychuk39362ed3bb11
diff --git a/lib/reporters/doc.js b/lib/reporters/doc.js
index 7e83e984..8175e433 100644
--- a/lib/reporters/doc.js
+++ b/lib/reporters/doc.js
@@ -3,7 +3,8 @@
* Module dependencies.
*/
-var Base = require('./base');
+var Base = require('./base')
+ , utils = require('../utils');
/**
* Expose `Doc`.
@@ -49,7 +50,7 @@ function Doc(runner) {
runner.on('pass', function(test){
console.log('%s <dt>%s</dt>', indent(), test.title);
- var code = clean(test.fn.toString());
+ var code = utils.escape(clean(test.fn.toString()));
console.log('%s <dd><pre><code>%s</code></pre></dd>', indent(), code);
});
diff --git a/lib/utils.js b/lib/utils.js
new file mode 100644
index 00000000..35570bce
--- /dev/null
+++ b/lib/utils.js
@@ -0,0 +1,16 @@
+
+/**
+ * Escape special characters in the given string of html.
+ *
+ * @param {String} html
+ * @return {String}
+ * @api private
+ */
+
+exports.escape = function(html) {
+ return String(html)
+ .replace(/&/g, '&amp;')
+ .replace(/"/g, '&quot;')
+ .replace(/</g, '&lt;')
+ .replace(/>/g, '&gt;');
+};
\ No newline at end of file