mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-22 07:46:16 -04:00
Tidied up string escape operations
This commit is contained in:
parent
55806db00f
commit
4b22a409e7
3 changed files with 16 additions and 10 deletions
|
@ -448,6 +448,7 @@ const StrUtils = {
|
|||
return outputs.join(sampleDelim);
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* @constant
|
||||
* @default
|
||||
|
@ -464,7 +465,7 @@ const StrUtils = {
|
|||
],
|
||||
|
||||
/**
|
||||
* Escapes a string for embedding in another string.
|
||||
* Escape string operation.
|
||||
*
|
||||
* @author Vel0x [dalemy@microsoft.com]
|
||||
*
|
||||
|
@ -483,8 +484,9 @@ const StrUtils = {
|
|||
return StrUtils._replaceByKeys(input, "unescaped", "escaped");
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Unescapes a string that was part of another string
|
||||
* Unescape string operation.
|
||||
*
|
||||
* @author Vel0x [dalemy@microsoft.com]
|
||||
*
|
||||
|
@ -503,9 +505,10 @@ const StrUtils = {
|
|||
return StrUtils._replaceByKeys(input, "escaped", "unescaped");
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Replaces all matching tokens in ESCAPE_REPLACEMENTS with the correction. The
|
||||
* ordering is determined by the pattern_key and the replacement_key.
|
||||
* ordering is determined by the patternKey and the replacementKey.
|
||||
*
|
||||
* @author Vel0x [dalemy@microsoft.com]
|
||||
* @author Matt C [matt@artemisbot.uk]
|
||||
|
@ -517,7 +520,10 @@ const StrUtils = {
|
|||
*/
|
||||
_replaceByKeys: function(input, patternKey, replacementKey) {
|
||||
let output = input;
|
||||
if (patternKey === "escaped") output = Utils.parseEscapedChars(input); // I've wrapped this to catch the \\x encoded characters
|
||||
|
||||
// Catch the \\x encoded characters
|
||||
if (patternKey === "escaped") output = Utils.parseEscapedChars(input);
|
||||
|
||||
StrUtils.ESCAPE_REPLACEMENTS.forEach(replacement => {
|
||||
output = output.split(replacement[patternKey]).join(replacement[replacementKey]);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue