This commit is contained in:
n1073645 2019-12-03 12:40:12 +00:00
parent a2ce9853b3
commit 0f4d1e70e0
2 changed files with 25 additions and 28 deletions

View file

@ -244,13 +244,25 @@ class Magic {
return results; return results;
} }
/**
* Uses the checks to validate the input/output of potential operations.
*
* @param {string} flag
* @param {array} sensible
* @param {Object} prevOp
* @param {number} depth
* @param {boolean} extLang
* @param {boolean} intensive
* @param {Object[]} recipeConfig
* @param {string} crib
*/
async regexesTests(flag, sensible, prevOp, depth, extLang, intensive, recipeConfig, crib) { async regexesTests(flag, sensible, prevOp, depth, extLang, intensive, recipeConfig, crib) {
let results = [] let results = [];
// Execute each of the matching operations, then recursively call the speculativeExecution() // Execute each of the matching operations, then recursively call the speculativeExecution()
// method on the resulting data, recording the properties of each option. // method on the resulting data, recording the properties of each option.
await Promise.all(sensible.map(async op => { await Promise.all(sensible.map(async op => {
const opConfig = { const opConfig = {
op: op.op, op: op.op,
args: op.args args: op.args
}, },
output = await this._runRecipe([opConfig]); output = await this._runRecipe([opConfig]);
@ -265,46 +277,31 @@ class Magic {
return; return;
} }
const outputRegexes = OperationConfig[op.op].outputRegexes;
switch (flag) { switch (flag) {
case "Input": case "Input":
const outputRegexes = OperationConfig[op.op].outputRegexes;
if (outputRegexes) if (outputRegexes)
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)
return;
} else {
if (!pattern.shouldMatch) if (!pattern.shouldMatch)
return; return;
} else {
if (pattern.shouldMatch)
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))) {
if (op.shouldMatch) if (!op.shouldMatch)
return; return;
} else { } else {
if (!op.shouldMatch) if (op.shouldMatch)
return; return;
} }
break; break;
default: default:
console.log("This is borked"); console.log("This is borked");
} }
/* if (flag) {
const outputRegexes = OperationConfig[op.op].outputRegexes;
if (outputRegexes)
for (const pattern of outputRegexes)
if (!(new RegExp(pattern.match, pattern.flags).test(Utils.arrayBufferToStr(output)))) {
if (pattern.shouldMatch)
return;
} else {
if (!pattern.shouldMatch)
return;
}
} else {
if(!(new RegExp(op.match, op.flags).test(Utils.arrayBufferToStr(output))))
return;
} */
const magic = new Magic(output, this.opPatterns), const magic = new Magic(output, this.opPatterns),
speculativeResults = await magic.speculativeExecution( speculativeResults = await magic.speculativeExecution(
depth-1, extLang, intensive, [...recipeConfig, opConfig], op.useful, crib); depth-1, extLang, intensive, [...recipeConfig, opConfig], op.useful, crib);

View file

@ -32,14 +32,14 @@ class URLDecode extends Operation {
args: [], args: [],
} }
], ],
/*[ /* [
{ {
match: "^(?:(http(s)?|ftp):\\/\\/)?[\\w.-]+(?:\\.[\\w\\.-]+)+[\\w\\-\\._~:/?#[\\]@!\\$&'\\(\\)\\*\\+,;=.]+$", match: "^(?:(http(s)?|ftp):\\/\\/)?[\\w.-]+(?:\\.[\\w\\.-]+)+[\\w\\-\\._~:/?#[\\]@!\\$&'\\(\\)\\*\\+,;=.]+$",
flags: "i", flags: "i",
shouldMatch: true, shouldMatch: true,
args: [] args: []
} }
]*/ ] */
); );
} }