Made sure we do not operation loop

This commit is contained in:
n1073645 2019-12-04 10:05:26 +00:00
parent b61fd59b60
commit c42aad7c82
2 changed files with 15 additions and 4 deletions

View file

@ -271,7 +271,7 @@ class Magic {
} catch (err) { } catch (err) {
return; 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)) { if (prevOp && op.op === prevOp.op && _buffersEqual(output, this.inputBuffer)) {
return; return;
} }
@ -284,7 +284,9 @@ class Magic {
const outputRegexes = OperationConfig[op.op].outputRegexes; const outputRegexes = OperationConfig[op.op].outputRegexes;
switch (flag) { switch (flag) {
case "Input": case "Input":
if (outputRegexes) if (outputRegexes) {
if (_buffersEqual(output, this.inputBuffer))
return;
for (const pattern of outputRegexes) for (const pattern of outputRegexes)
if (new RegExp(pattern.match, pattern.flags).test(Utils.arrayBufferToStr(output))) { if (new RegExp(pattern.match, pattern.flags).test(Utils.arrayBufferToStr(output))) {
if (!pattern.shouldMatch) if (!pattern.shouldMatch)
@ -293,6 +295,7 @@ class Magic {
if (pattern.shouldMatch) if (pattern.shouldMatch)
return; return;
} }
}
break; break;
case "Output": case "Output":
if (new RegExp(op.match, op.flags).test(Utils.arrayBufferToStr(output))) { if (new RegExp(op.match, op.flags).test(Utils.arrayBufferToStr(output))) {
@ -302,9 +305,9 @@ class Magic {
if (op.shouldMatch) if (op.shouldMatch)
return; return;
} }
console.log(output);
console.log(this.inputBuffer);
break; break;
default:
console.log("This is borked");
} }
const magic = new Magic(output, this.opPatterns), const magic = new Magic(output, this.opPatterns),
speculativeResults = await magic.speculativeExecution( speculativeResults = await magic.speculativeExecution(

View file

@ -89,6 +89,14 @@ class DefangURL extends Operation {
flags: "i", flags: "i",
args: [true, true, true, "Everything"], args: [true, true, true, "Everything"],
} }
],
[
{
match: "^\\s*(h(tt|xx)ps?|ftp)(://|\\[://\\])(-(\\.|\\[\\.\\]))?([^\\s/?\\.\\[\\]#-]+(\\.|\\[\\.\\])?)+(/\\S*)?\\s*$",
flags: "i",
shouldMatch: true,
args: [true, true, true, "Everything"],
}
]); ]);
} }