feat: add Raw option for Jq operation (#2237)
This commit is contained in:
parent
7f4f90e4f3
commit
290f824e18
@ -30,7 +30,12 @@ class Jq extends Operation {
|
|||||||
name: "Query",
|
name: "Query",
|
||||||
type: "string",
|
type: "string",
|
||||||
value: ""
|
value: ""
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
name: "Raw",
|
||||||
|
type: "boolean",
|
||||||
|
value: false
|
||||||
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +45,7 @@ class Jq extends Operation {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
const [query] = args;
|
const [query, raw] = args;
|
||||||
let result;
|
let result;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -48,8 +53,11 @@ class Jq extends Operation {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new OperationError(`Invalid jq expression: ${err.message}`);
|
throw new OperationError(`Invalid jq expression: ${err.message}`);
|
||||||
}
|
}
|
||||||
|
if (raw && typeof result === "string") {
|
||||||
return JSON.stringify(result);
|
return result;
|
||||||
|
} else {
|
||||||
|
return JSON.stringify(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
32
tests/operations/tests/Jq.mjs
Normal file
32
tests/operations/tests/Jq.mjs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/**
|
||||||
|
* Jq tests.
|
||||||
|
*
|
||||||
|
* @author rtpt-romankarwacik [roman.karwacik@redteam-pentesting.de]
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
import TestRegister from "../../lib/TestRegister.mjs";
|
||||||
|
|
||||||
|
TestRegister.addTests([
|
||||||
|
{
|
||||||
|
name: "Get raw JSON Property",
|
||||||
|
input: '{"data": "testString\\u0000"}',
|
||||||
|
expectedOutput: "testString\u0000",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Jq",
|
||||||
|
args: [".data", true],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Get JSON Property",
|
||||||
|
input: '{"data": "testString\\u0000"}',
|
||||||
|
expectedOutput: "\"testString\\u0000\"",
|
||||||
|
recipeConfig: [
|
||||||
|
{
|
||||||
|
op: "Jq",
|
||||||
|
args: [".data", false],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]);
|
||||||
Loading…
x
Reference in New Issue
Block a user