浏览代码

Added tests + fixes for PR

- actually removed prev func
- shuffled some stuff around
Matt C 8 年之前
父节点
当前提交
6698a2ac13

+ 0 - 1
src/core/config/Categories.js

@@ -173,7 +173,6 @@ const Categories = [
             "Tail",
             "Tail",
             "Count occurrences",
             "Count occurrences",
             "Expand alphabet range",
             "Expand alphabet range",
-            "Parse escaped string",
             "Drop bytes",
             "Drop bytes",
             "Take bytes",
             "Take bytes",
             "Pad lines",
             "Pad lines",

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

@@ -3206,13 +3206,6 @@ const OperationConfig = {
             }
             }
         ]
         ]
     },
     },
-    "Parse escaped string": {
-        description: "Replaces escaped characters with the bytes they represent.<br><br>e.g.<code>Hello\\nWorld</code> becomes <code>Hello<br>World</code>",
-        run: StrUtils.runParseEscapedString,
-        inputType: "string",
-        outputType: "string",
-        args: []
-    },
     "TCP/IP Checksum": {
     "TCP/IP Checksum": {
         description: "Calculates the checksum for a TCP (Transport Control Protocol) or IP (Internet Protocol) header from an input of raw bytes.",
         description: "Calculates the checksum for a TCP (Transport Control Protocol) or IP (Internet Protocol) header from an input of raw bytes.",
         run: Checksum.runTCPIP,
         run: Checksum.runTCPIP,

+ 5 - 1
src/core/operations/StrUtils.js

@@ -458,6 +458,9 @@ const StrUtils = {
         {"escaped": "\\\"", "unescaped": "\""},
         {"escaped": "\\\"", "unescaped": "\""},
         {"escaped": "\\n", "unescaped": "\n"},
         {"escaped": "\\n", "unescaped": "\n"},
         {"escaped": "\\r", "unescaped": "\r"},
         {"escaped": "\\r", "unescaped": "\r"},
+        {"escaped": "\\t", "unescaped": "\t"},
+        {"escaped": "\\b", "unescaped": "\b"},
+        {"escaped": "\\f", "unescaped": "\f"},
     ],
     ],
 
 
     /**
     /**
@@ -497,7 +500,7 @@ const StrUtils = {
      * World`
      * World`
      */
      */
     runUnescape: function(input, args) {
     runUnescape: function(input, args) {
-        return StrUtils._replaceByKeys(Utils.parseEscapedChars(input), "escaped", "unescaped");
+        return StrUtils._replaceByKeys(input, "escaped", "unescaped");
     },
     },
 
 
     /**
     /**
@@ -514,6 +517,7 @@ const StrUtils = {
      */
      */
     _replaceByKeys: function(input, patternKey, replacementKey) {
     _replaceByKeys: function(input, patternKey, replacementKey) {
         let output = input;
         let output = input;
+        if (patternKey === "escaped") output = Utils.parseEscapedChars(input); // I've wrapped this to catch the \\x encoded characters
         StrUtils.ESCAPE_REPLACEMENTS.forEach(replacement => {
         StrUtils.ESCAPE_REPLACEMENTS.forEach(replacement => {
             output = output.split(replacement[patternKey]).join(replacement[replacementKey]);
             output = output.split(replacement[patternKey]).join(replacement[replacementKey]);
         });
         });

+ 44 - 0
test/tests/operations/StrUtils.js

@@ -232,4 +232,48 @@ TestRegister.addTests([
             }
             }
         ],
         ],
     },
     },
+    {
+        name: "Escape String: quotes",
+        input: "Hello \"World\"! Escape 'these' quotes.",
+        expectedOutput: "Hello \\\"World\\\"! Escape \\'these\\' quotes.",
+        recipeConfig: [
+            {
+                "op": "Escape String",
+                "args": []
+            }
+        ],
+    },
+    {
+        name: "Escape String: special characters",
+        input: "Fizz & buzz\n\ttabbed newline\rcarriage returned line\nbackspace character: \"\" form feed character: \"\"",
+        expectedOutput: "Fizz & buzz\\n\\ttabbed newline\\rcarriage returned line\\nbackspace character: \\\"\\b\\\" form feed character: \\\"\\f\\\"",
+        recipeConfig: [
+            {
+                "op": "Escape String",
+                "args": []
+            }
+        ],
+    },
+    {
+        name: "Unescape String: quotes",
+        input: "Hello \\\"World\\\"! Escape \\'these\\' quotes.",
+        expectedOutput: "Hello \"World\"! Escape 'these' quotes.",
+        recipeConfig: [
+            {
+                "op": "Unescape String",
+                "args": []
+            }
+        ],
+    },
+    {
+        name: "Unescape String: special characters",
+        input: "Fizz \x26 buzz\\n\\ttabbed newline\\rcarriage returned line\\nbackspace character: \\\"\\b\\\" form feed character: \\\"\\f\\\"",
+        expectedOutput: "Fizz & buzz\n\ttabbed newline\rcarriage returned line\nbackspace character: \"\" form feed character: \"\"",
+        recipeConfig: [
+            {
+                "op": "Unescape String",
+                "args": []
+            }
+        ],
+    },
 ]);
 ]);