Fix invalid XML from the CLI xml reporter (#217)

* Remove javascriptExecutionTree from the xml output
* Change JSON structure for offenders classified by url
* Remove special chars from XML output
This commit is contained in:
Gaël Métais
2016-12-28 23:51:18 +08:00
committed by GitHub
parent bdf5f82959
commit 4911d61d78
5 changed files with 149204 additions and 11 deletions
+21 -2
View File
@@ -84,8 +84,27 @@ if (cli.flags.reporter && cli.flags.reporter !== 'json' && cli.flags.reporter !=
debug('Success');
switch(cli.flags.reporter) {
case 'xml':
var serializer = new EasyXml();
console.log(serializer.render(data));
var serializer = new EasyXml({
manifest: true
});
// Remove some heavy parts of the results object
delete data.toolsResults;
delete data.javascriptExecutionTree;
var xmlOutput = serializer.render(data);
// Remove special chars from XML tags: # [ ]
xmlOutput = xmlOutput.replace(/<([^>]*)#([^>]*)>/g, '<$1>');
xmlOutput = xmlOutput.replace(/<([^>]*)\[([^>]*)>/g, '<$1>');
xmlOutput = xmlOutput.replace(/<([^>]*)\]([^>]*)>/g, '<$1>');
// Remove special chars from text content: \n \0
xmlOutput = xmlOutput.replace(/(<[a-zA-Z]*>[^<]*)\n([^<]*<\/[a-zA-Z]*>)/g, '$1$2');
xmlOutput = xmlOutput.replace(/\0/g, '');
xmlOutput = xmlOutput.replace(/\uFFFF/g, '');
console.log(xmlOutput);
break;
default:
console.log(JSON.stringify(data, null, 2));