Browse Source

Regexes are now checked for 0-length matches and incremented manually to avoid infinite loops

n1474335 7 years ago
parent
commit
ec02b7deda
3 changed files with 15 additions and 3 deletions
  1. 0 3
      src/core/config/OperationConfig.js
  2. 5 0
      src/core/operations/Extract.js
  3. 10 0
      src/core/operations/Regex.js

+ 0 - 3
src/core/config/OperationConfig.js

@@ -2061,7 +2061,6 @@ const OperationConfig = {
     "Find / Replace": {
         module: "Regex",
         description: "Replaces all occurrences of the first string with the second.<br><br> Includes support for regular expressions (regex), simple strings and extended strings (which support \\n, \\r, \\t, \\b, \\f and escaped hex bytes using \\x notation, e.g. \\x00 for a null byte).",
-        manualBake: true,
         inputType: "string",
         outputType: "string",
         args: [
@@ -2139,7 +2138,6 @@ const OperationConfig = {
     "Filter": {
         module: "Default",
         description: "Splits up the input using the specified delimiter and then filters each branch based on a regular expression.",
-        manualBake: true,
         inputType: "string",
         outputType: "string",
         args: [
@@ -2302,7 +2300,6 @@ const OperationConfig = {
     "Regular expression": {
         module: "Regex",
         description: "Define your own regular expression (regex) to search the input data with, optionally choosing from a list of pre-defined patterns.",
-        manualBake: true,
         inputType: "string",
         outputType: "html",
         args: [

+ 5 - 0
src/core/operations/Extract.js

@@ -29,6 +29,11 @@ const Extract = {
             match;
 
         while ((match = searchRegex.exec(input))) {
+            // Moves pointer when an empty string is matched (prevents infinite loop)
+            if (match.index === searchRegex.lastIndex) {
+                searchRegex.lastIndex++;
+            }
+
             if (removeRegex && removeRegex.test(match[0]))
                 continue;
             total++;

+ 10 - 0
src/core/operations/Regex.js

@@ -208,6 +208,11 @@ const Regex = {
             total = 0;
 
         while ((m = regex.exec(input))) {
+            // Moves pointer when an empty string is matched (prevents infinite loop)
+            if (m.index === regex.lastIndex) {
+                regex.lastIndex++;
+            }
+
             // Add up to match
             output += Utils.escapeHtml(input.slice(i, m.index));
 
@@ -248,6 +253,11 @@ const Regex = {
             match;
 
         while ((match = regex.exec(input))) {
+            // Moves pointer when an empty string is matched (prevents infinite loop)
+            if (match.index === regex.lastIndex) {
+                regex.lastIndex++;
+            }
+
             total++;
             if (matches) {
                 output += match[0] + "\n";