mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 23:36:16 -04:00
Merge branch 'wh0-backslash'
This commit is contained in:
commit
08e4232166
5 changed files with 36 additions and 20 deletions
|
@ -201,9 +201,8 @@ class Utils {
|
||||||
* Utils.parseEscapedChars("\\n");
|
* Utils.parseEscapedChars("\\n");
|
||||||
*/
|
*/
|
||||||
static parseEscapedChars(str) {
|
static parseEscapedChars(str) {
|
||||||
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, b) {
|
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) {
|
||||||
if (a === "\\") return "\\"+b;
|
switch (a[0]) {
|
||||||
switch (b[0]) {
|
|
||||||
case "\\":
|
case "\\":
|
||||||
return "\\";
|
return "\\";
|
||||||
case "0":
|
case "0":
|
||||||
|
@ -214,7 +213,7 @@ class Utils {
|
||||||
case "5":
|
case "5":
|
||||||
case "6":
|
case "6":
|
||||||
case "7":
|
case "7":
|
||||||
return String.fromCharCode(parseInt(b, 8));
|
return String.fromCharCode(parseInt(a, 8));
|
||||||
case "b":
|
case "b":
|
||||||
return "\b";
|
return "\b";
|
||||||
case "t":
|
case "t":
|
||||||
|
@ -232,12 +231,12 @@ class Utils {
|
||||||
case "'":
|
case "'":
|
||||||
return "'";
|
return "'";
|
||||||
case "x":
|
case "x":
|
||||||
return String.fromCharCode(parseInt(b.substr(1), 16));
|
return String.fromCharCode(parseInt(a.substr(1), 16));
|
||||||
case "u":
|
case "u":
|
||||||
if (b[1] === "{")
|
if (a[1] === "{")
|
||||||
return String.fromCodePoint(parseInt(b.slice(2, -1), 16));
|
return String.fromCodePoint(parseInt(a.slice(2, -1), 16));
|
||||||
else
|
else
|
||||||
return String.fromCharCode(parseInt(b.substr(1), 16));
|
return String.fromCharCode(parseInt(a.substr(1), 16));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,8 @@ import "./tests/operations.mjs";
|
||||||
import "./tests/File.mjs";
|
import "./tests/File.mjs";
|
||||||
import "./tests/Dish.mjs";
|
import "./tests/Dish.mjs";
|
||||||
import "./tests/NodeDish.mjs";
|
import "./tests/NodeDish.mjs";
|
||||||
|
import "./tests/Utils.mjs";
|
||||||
|
import "./tests/Categories.mjs";
|
||||||
|
|
||||||
const testStatus = {
|
const testStatus = {
|
||||||
allTestsPassing: true,
|
allTestsPassing: true,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import TestRegister from "../lib/TestRegister.mjs";
|
import TestRegister from "../../lib/TestRegister.mjs";
|
||||||
import Categories from "../../src/core/config/Categories.json";
|
import Categories from "../../../src/core/config/Categories.json";
|
||||||
import OperationConfig from "../../src/core/config/OperationConfig.json";
|
import OperationConfig from "../../../src/core/config/OperationConfig.json";
|
||||||
import it from "../node/assertionHandler.mjs";
|
import it from "../assertionHandler.mjs";
|
||||||
import assert from "assert";
|
import assert from "assert";
|
||||||
|
|
||||||
TestRegister.addApiTests([
|
TestRegister.addApiTests([
|
23
tests/node/tests/Utils.mjs
Normal file
23
tests/node/tests/Utils.mjs
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
import TestRegister from "../../lib/TestRegister.mjs";
|
||||||
|
import Utils from "../../../src/core/Utils.mjs";
|
||||||
|
import it from "../assertionHandler.mjs";
|
||||||
|
import assert from "assert";
|
||||||
|
|
||||||
|
TestRegister.addApiTests([
|
||||||
|
it("Utils: should parse six backslashes correctly", () => {
|
||||||
|
assert.equal(Utils.parseEscapedChars("\\\\\\\\\\\\"), "\\\\\\");
|
||||||
|
}),
|
||||||
|
|
||||||
|
it("Utils: should parse escaped quotes correctly", () => {
|
||||||
|
assert.equal(Utils.parseEscapedChars("\\'"), "'");
|
||||||
|
}),
|
||||||
|
|
||||||
|
it("Utils: should parse escaped quotes and backslashes correctly", () => {
|
||||||
|
assert.equal(Utils.parseEscapedChars("\\\\'"), "\\'");
|
||||||
|
}),
|
||||||
|
|
||||||
|
it("Utils: should parse escaped quotes and escaped backslashes correctly", () => {
|
||||||
|
assert.equal(Utils.parseEscapedChars("\\\\\\'"), "\\'");
|
||||||
|
}),
|
||||||
|
|
||||||
|
]);
|
|
@ -17,11 +17,6 @@ import {
|
||||||
} from "../lib/utils.mjs";
|
} from "../lib/utils.mjs";
|
||||||
|
|
||||||
import TestRegister from "../lib/TestRegister.mjs";
|
import TestRegister from "../lib/TestRegister.mjs";
|
||||||
|
|
||||||
// Generic tests
|
|
||||||
import "./Categories.mjs";
|
|
||||||
|
|
||||||
// Operation tests
|
|
||||||
import "./tests/BCD.mjs";
|
import "./tests/BCD.mjs";
|
||||||
import "./tests/BSON.mjs";
|
import "./tests/BSON.mjs";
|
||||||
import "./tests/BaconCipher.mjs";
|
import "./tests/BaconCipher.mjs";
|
||||||
|
@ -111,8 +106,5 @@ setLongTestFailure();
|
||||||
|
|
||||||
const logOpsTestReport = logTestReport.bind(null, testStatus);
|
const logOpsTestReport = logTestReport.bind(null, testStatus);
|
||||||
|
|
||||||
TestRegister.runApiTests()
|
|
||||||
.then(logOpsTestReport);
|
|
||||||
|
|
||||||
TestRegister.runTests()
|
TestRegister.runTests()
|
||||||
.then(logOpsTestReport);
|
.then(logOpsTestReport);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue