From c42aad7c8218c79f963410504e16e0e20163a183 Mon Sep 17 00:00:00 2001 From: n1073645 Date: Wed, 4 Dec 2019 10:05:26 +0000 Subject: [PATCH] Made sure we do not operation loop --- src/core/lib/Magic.mjs | 11 +++++++---- src/core/operations/DefangURL.mjs | 8 ++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/core/lib/Magic.mjs b/src/core/lib/Magic.mjs index db436009..5e5e0631 100644 --- a/src/core/lib/Magic.mjs +++ b/src/core/lib/Magic.mjs @@ -271,7 +271,7 @@ class Magic { } catch (err) { return; } - // If the recipe is repeating and returning the same data, do not continue + // If the recipe is repeating and returning the same data, do not continue if (prevOp && op.op === prevOp.op && _buffersEqual(output, this.inputBuffer)) { return; } @@ -284,7 +284,9 @@ class Magic { const outputRegexes = OperationConfig[op.op].outputRegexes; switch (flag) { case "Input": - if (outputRegexes) + if (outputRegexes) { + if (_buffersEqual(output, this.inputBuffer)) + return; for (const pattern of outputRegexes) if (new RegExp(pattern.match, pattern.flags).test(Utils.arrayBufferToStr(output))) { if (!pattern.shouldMatch) @@ -293,6 +295,7 @@ class Magic { if (pattern.shouldMatch) return; } + } break; case "Output": if (new RegExp(op.match, op.flags).test(Utils.arrayBufferToStr(output))) { @@ -302,9 +305,9 @@ class Magic { if (op.shouldMatch) return; } + console.log(output); + console.log(this.inputBuffer); break; - default: - console.log("This is borked"); } const magic = new Magic(output, this.opPatterns), speculativeResults = await magic.speculativeExecution( diff --git a/src/core/operations/DefangURL.mjs b/src/core/operations/DefangURL.mjs index 658dc80a..0c9767c1 100644 --- a/src/core/operations/DefangURL.mjs +++ b/src/core/operations/DefangURL.mjs @@ -89,6 +89,14 @@ class DefangURL extends Operation { flags: "i", args: [true, true, true, "Everything"], } + ], + [ + { + match: "^\\s*(h(tt|xx)ps?|ftp)(://|\\[://\\])(-(\\.|\\[\\.\\]))?([^\\s/?\\.\\[\\]#-]+(\\.|\\[\\.\\])?)+(/\\S*)?\\s*$", + flags: "i", + shouldMatch: true, + args: [true, true, true, "Everything"], + } ]); }