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) {
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(

View file

@ -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"],
}
]);
}