Skip to content

Commit 0cf7bca

Browse files
authored
Fix import operations with special chars in them (#1040)
Co-authored-by: jg42526 <210032080+jg42526@users.noreply.github.com> (fixed test broken by a dependency updated elsewhere)
1 parent 4e8f0c3 commit 0cf7bca

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

src/node/apiUtils.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export function removeSubheadingsFromArray(array) {
6666
* @param str
6767
*/
6868
export function sanitise(str) {
69-
return str.replace(/ /g, "").toLowerCase();
69+
return str.replace(/[/\s.-]/g, "").toLowerCase();
7070
}
7171

7272

tests/node/tests/nodeApi.mjs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,42 @@ TestRegister.addApiTests([
345345
assert.strictEqual(result.toString(), "begin_something_aaaaaaaaaaaaaa_end_something");
346346
}),
347347

348+
it("chef.bake: should accept operation names from Chef Website which contain forward slash", () => {
349+
const result = chef.bake("I'll have the test salmon", [
350+
{ "op": "Find / Replace",
351+
"args": [{ "option": "Regex", "string": "test" }, "good", true, false, true, false]}
352+
]);
353+
assert.strictEqual(result.toString(), "I'll have the good salmon");
354+
}),
355+
356+
it("chef.bake: should accept operation names from Chef Website which contain a hyphen", () => {
357+
const result = chef.bake("I'll have the test salmon", [
358+
{ "op": "Adler-32 Checksum",
359+
"args": [] }
360+
]);
361+
assert.strictEqual(result.toString(), "6e4208f8");
362+
}),
363+
364+
it("chef.bake: should accept operation names from Chef Website which contain a period", () => {
365+
const result = chef.bake("30 13 02 01 05 16 0e 41 6e 79 62 6f 64 79 20 74 68 65 72 65 3f", [
366+
{ "op": "Parse ASN.1 hex string",
367+
"args": [0, 32] }
368+
]);
369+
assert.strictEqual(result.toString(), `SEQUENCE
370+
INTEGER 05
371+
IA5String 'Anybody there?'
372+
`);
373+
}),
374+
375+
it("Excluded operations: throw a sensible error when you try and call one", () => {
376+
try {
377+
chef.fork();
378+
} catch (e) {
379+
assert.strictEqual(e.type, "ExcludedOperationError");
380+
assert.strictEqual(e.message, "Sorry, the Fork operation is not available in the Node.js version of CyberChef.");
381+
}
382+
}),
383+
348384
it("chef.bake: cannot accept flowControl operations in recipe", () => {
349385
assert.throws(() => chef.bake("some input", "magic"), {
350386
name: "TypeError",

0 commit comments

Comments
 (0)