Skip to content

armgit / mocha

Public Imported from GitHub
0

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

Removing sys require, and using utils.escape

Joshua Krall1479ee23b055
diff --git a/lib/reporters/xunit.js b/lib/reporters/xunit.js
index 1159cc7e..de850711 100644
--- a/lib/reporters/xunit.js
+++ b/lib/reporters/xunit.js
@@ -1,5 +1,5 @@
var Base = require('./base');
-var sys = require('sys');
+var utils = require('../utils');
/**
* Expose `XUnit`.
@@ -53,7 +53,7 @@ function processTest(test) {
}
function pendingTestTag(test) {
- return tag('skipped', { message: encode(test.err.stack || test.err) }, true);
+ return tag('skipped', { message: utils.escape(test.err.stack || test.err) }, true);
}
function failedTestTag(test) {
@@ -63,26 +63,16 @@ function failedTestTag(test) {
// check for the result of the stringifying.
if ('[object Error]' == str) str = test.err.message;
- var attributes = { message: encode(str) };
+ var attributes = { message: utils.escape(str) };
return tag('failure', attributes, false, cdata(test.err.stack));
}
-function encode(value) {
- return !value ? value :
- String(value)
- .replace(/&/g, '&')
- .replace(/>/g, '>')
- .replace(/</g, '&lt;')
- .replace(/"/g, '&quot;')
- .replace(/\u001b\[\d{1,2}m/g, '');
-}
-
function tag(name, attribs, single, content) {
var tag;
var end = single ? ' />' : '>'
var strAttr = [];
for (var attr in attribs) {
- attribs.hasOwnProperty(attr) && strAttr.push(attr + '="' + encode(attribs[attr]) + '"');
+ attribs.hasOwnProperty(attr) && strAttr.push(attr + '="' + utils.escape(attribs[attr]) + '"');
}
tag = '<' + name + (strAttr.length? ' ' + strAttr.join(' ') : '' ) + end;
@@ -95,7 +85,7 @@ function end(name) {
}
function cdata(data) {
- return '<![CDATA[' + encode(data) + ']]>';
+ return '<![CDATA[' + utils.escape(data) + ']]>';
}
XUnit.prototype.__proto__ = Base.prototype;