mirror of
https://github.com/gchq/CyberChef.git
synced 2025-05-14 18:16:53 -04:00
Merge branch 'gchq:master' into master
This commit is contained in:
commit
7ca472279c
9 changed files with 650 additions and 8 deletions
|
@ -370,6 +370,7 @@
|
|||
"Regular expression",
|
||||
"XPath expression",
|
||||
"JPath expression",
|
||||
"Jsonata Query",
|
||||
"CSS selector",
|
||||
"Extract EXIF",
|
||||
"Extract ID3",
|
||||
|
|
65
src/core/operations/Jsonata.mjs
Normal file
65
src/core/operations/Jsonata.mjs
Normal file
|
@ -0,0 +1,65 @@
|
|||
/**
|
||||
* @author Jon K (jon@ajarsoftware.com)
|
||||
* @copyright Crown Copyright 2016
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import jsonata from "jsonata";
|
||||
import Operation from "../Operation.mjs";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
|
||||
/**
|
||||
* Jsonata Query operation
|
||||
*/
|
||||
class JsonataQuery extends Operation {
|
||||
/**
|
||||
* JsonataQuery constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Jsonata Query";
|
||||
this.module = "Code";
|
||||
this.description =
|
||||
"Query and transform JSON data with a jsonata query.";
|
||||
this.infoURL = "https://docs.jsonata.org/overview.html";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
{
|
||||
name: "Query",
|
||||
type: "text",
|
||||
value: "string",
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
async run(input, args) {
|
||||
const [query] = args;
|
||||
let result, jsonObj;
|
||||
|
||||
try {
|
||||
jsonObj = JSON.parse(input);
|
||||
} catch (err) {
|
||||
throw new OperationError(`Invalid input JSON: ${err.message}`);
|
||||
}
|
||||
|
||||
try {
|
||||
const expression = jsonata(query);
|
||||
result = await expression.evaluate(jsonObj);
|
||||
} catch (err) {
|
||||
throw new OperationError(
|
||||
`Invalid Jsonata Expression: ${err.message}`
|
||||
);
|
||||
}
|
||||
|
||||
return JSON.stringify(result === undefined ? "" : result);
|
||||
}
|
||||
}
|
||||
|
||||
export default JsonataQuery;
|
|
@ -125,6 +125,7 @@ class Manager {
|
|||
window.addEventListener("focus", this.window.windowFocus.bind(this.window));
|
||||
window.addEventListener("statechange", this.app.stateChange.bind(this.app));
|
||||
window.addEventListener("popstate", this.app.popState.bind(this.app));
|
||||
window.addEventListener("message", this.input.handlePostMessage.bind(this.input));
|
||||
|
||||
// Controls
|
||||
document.getElementById("bake").addEventListener("click", this.controls.bakeClick.bind(this.controls));
|
||||
|
|
|
@ -1654,6 +1654,23 @@ class InputWaiter {
|
|||
this.changeTab(inputNum, this.app.options.syncTabs);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for incoming postMessages
|
||||
* If the events data has a `type` property set to `dataSubmit`
|
||||
* the value property is set to the current input
|
||||
* @param {event} e
|
||||
* @param {object} e.data
|
||||
* @param {string} e.data.type - the type of request, currently the only value is "dataSubmit"
|
||||
* @param {string} e.data.value - the value of the message
|
||||
*/
|
||||
handlePostMessage(e) {
|
||||
log.debug(e);
|
||||
if ("data" in e && "id" in e.data && "value" in e.data) {
|
||||
if (e.data.id === "setInput") {
|
||||
this.setInput(e.data.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default InputWaiter;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue