mirror of
https://github.com/gchq/CyberChef.git
synced 2025-05-09 15:55:01 -04:00
XML Validator added
This commit is contained in:
parent
4c3324aea1
commit
2e28a4d737
2 changed files with 60 additions and 0 deletions
|
@ -356,6 +356,7 @@
|
|||
"JSON Minify",
|
||||
"XML Beautify",
|
||||
"XML Minify",
|
||||
"XML Validator",
|
||||
"SQL Beautify",
|
||||
"SQL Minify",
|
||||
"CSS Beautify",
|
||||
|
|
59
src/core/operations/XMLValidator.mjs
Normal file
59
src/core/operations/XMLValidator.mjs
Normal file
|
@ -0,0 +1,59 @@
|
|||
/**
|
||||
* @author n1073645 [n1073645@gmail.com]
|
||||
* @copyright Crown Copyright 2020
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
|
||||
/**
|
||||
* XML Validator operation
|
||||
*/
|
||||
class XMLValidator extends Operation {
|
||||
|
||||
/**
|
||||
* XMLValidator constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "XML Validator";
|
||||
this.module = "Default";
|
||||
this.description = "";
|
||||
this.infoURL = "";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
|
||||
const DOMParser = require("xmldom").DOMParser;
|
||||
|
||||
try {
|
||||
// Overwrite error handler since the built-in one does not raise exceptions.
|
||||
(new DOMParser({errorHandler: {
|
||||
warning: (msg) => {
|
||||
throw new OperationError(msg);
|
||||
},
|
||||
error: (msg) => {
|
||||
throw new OperationError(msg);
|
||||
},
|
||||
fatalError: (msg) => {
|
||||
throw new OperationError(msg);
|
||||
},
|
||||
}})).parseFromString(input);
|
||||
} catch (err) {
|
||||
throw new OperationError(err);
|
||||
}
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
export default XMLValidator;
|
Loading…
Add table
Add a link
Reference in a new issue