Skip to content

Commit a73decc

Browse files
committed
Merge branch 'master' of https://github.com/gariev/CyberChef
2 parents f332ca4 + 026e9ca commit a73decc

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

src/core/Utils.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ class Utils {
206206
* Utils.parseEscapedChars("\\n");
207207
*/
208208
static parseEscapedChars(str) {
209-
return str.replace(/\\([bfnrtv'"]|[0-3][0-7]{2}|[0-7]{1,2}|x[\da-fA-F]{2}|u[\da-fA-F]{4}|u\{[\da-fA-F]{1,6}\}|\\)/g, function(m, a) {
209+
return str.replace(/\\([abfnrtv'"]|[0-3][0-7]{2}|[0-7]{1,2}|x[\da-fA-F]{2}|u[\da-fA-F]{4}|u\{[\da-fA-F]{1,6}\}|\\)/g, function(m, a) {
210210
switch (a[0]) {
211211
case "\\":
212212
return "\\";
@@ -219,6 +219,8 @@ class Utils {
219219
case "6":
220220
case "7":
221221
return String.fromCharCode(parseInt(a, 8));
222+
case "a":
223+
return String.fromCharCode(7);
222224
case "b":
223225
return "\b";
224226
case "t":

tests/operations/index.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ import "./tests/SIGABA.mjs";
120120
import "./tests/ELFInfo.mjs";
121121
import "./tests/Subsection.mjs";
122122
import "./tests/CaesarBoxCipher.mjs";
123+
import "./tests/UnescapeString.mjs";
123124
import "./tests/LS47.mjs";
124125
import "./tests/LZString.mjs";
125126

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* UnescapeString tests.
3+
*
4+
* @copyright Crown Copyright 2022
5+
* @license Apache-2.0
6+
*/
7+
import TestRegister from "../../lib/TestRegister.mjs";
8+
9+
TestRegister.addTests([
10+
{
11+
name: "UnescapeString: escape sequences",
12+
input: "\\a\\b\\f\\n\\r\\t\\v\\'\\\"",
13+
expectedOutput: String.fromCharCode(0x07, 0x08, 0x0c, 0x0a, 0x0d, 0x09,
14+
0x0b, 0x27, 0x22),
15+
recipeConfig: [
16+
{
17+
op: "Unescape string",
18+
args: [],
19+
},
20+
],
21+
},
22+
{
23+
name: "UnescapeString: octals",
24+
input: "\\0\\01\\012\\1\\12",
25+
expectedOutput: String.fromCharCode(0, 1, 10, 1, 10),
26+
recipeConfig: [
27+
{
28+
op: "Unescape string",
29+
args: [],
30+
},
31+
],
32+
},
33+
{
34+
name: "UnescapeString: hexadecimals",
35+
input: "\\x00\\xAA\\xaa",
36+
expectedOutput: String.fromCharCode(0, 170, 170),
37+
recipeConfig: [
38+
{
39+
op: "Unescape string",
40+
args: [],
41+
},
42+
],
43+
},
44+
{
45+
name: "UnescapeString: unicode",
46+
input: "\\u0061\\u{0062}",
47+
expectedOutput: "ab",
48+
recipeConfig: [
49+
{
50+
op: "Unescape string",
51+
args: [],
52+
},
53+
],
54+
},
55+
]);

0 commit comments

Comments
 (0)