mirror of
https://github.com/gchq/CyberChef.git
synced 2025-05-09 07:45:00 -04:00
correct warnings
This commit is contained in:
parent
bf31f48e06
commit
3dcea288bf
1 changed files with 20 additions and 21 deletions
|
@ -5,7 +5,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Operation from "../Operation";
|
import Operation from "../Operation";
|
||||||
import OperationError from "../errors/OperationError";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To Python bytes operation
|
* To Python bytes operation
|
||||||
|
@ -33,18 +32,18 @@ class ToPythonBytes extends Operation {
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
let data = new Uint8Array(input);
|
const data = new Uint8Array(input);
|
||||||
if (!data) return "b''";
|
if (!data) return "b''";
|
||||||
|
|
||||||
// First pass to decide which quote to use
|
// First pass to decide which quote to use
|
||||||
// single quote is prefered
|
// single quote is prefered
|
||||||
let onlySingleQuote = false;
|
let onlySingleQuote = false;
|
||||||
for (let i = 0; i < data.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
if(data[i] == 0x22) { // 0x22 <-> "
|
if (data[i] === 0x22) { // 0x22 <-> "
|
||||||
onlySingleQuote = false;
|
onlySingleQuote = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(data[i] == 0x27) { // 0x27 <-> '
|
if (data[i] === 0x27) { // 0x27 <-> '
|
||||||
onlySingleQuote = true;
|
onlySingleQuote = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,20 +55,20 @@ class ToPythonBytes extends Operation {
|
||||||
// Second pass to convert byte array in Python bytes literal
|
// Second pass to convert byte array in Python bytes literal
|
||||||
let output = "";
|
let output = "";
|
||||||
for (let i = 0; i < data.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
if(data[i] == 0x09) {
|
if (data[i] === 0x09) {
|
||||||
output += '\\t';
|
output += "\\t";
|
||||||
} else if(data[i] == 0x0a) {
|
} else if (data[i] === 0x0a) {
|
||||||
output += '\\n';
|
output += "\\n";
|
||||||
} else if(data[i] == 0x0d) {
|
} else if (data[i] === 0x0d) {
|
||||||
output += '\\r';
|
output += "\\r";
|
||||||
} else if(data[i] == 0x22 && !singleQuoted) {
|
} else if (data[i] === 0x22 && !singleQuoted) {
|
||||||
output += '\\"';
|
output += '\\"';
|
||||||
} else if(data[i] == 0x27 && singleQuoted) {
|
} else if (data[i] === 0x27 && singleQuoted) {
|
||||||
output += "\\'";
|
output += "\\'";
|
||||||
} else if(data[i] == 0x5c) {
|
} else if (data[i] === 0x5c) {
|
||||||
output += '\\';
|
output += "\\";
|
||||||
} else if (data[i] < 0x20 || data[i] > 0x7e) {
|
} else if (data[i] < 0x20 || data[i] > 0x7e) {
|
||||||
output += '\\x' + data[i].toString(16).padStart(2,0);
|
output += "\\x" + data[i].toString(16).padStart(2, 0);
|
||||||
} else {
|
} else {
|
||||||
output += String.fromCharCode(data[i]);
|
output += String.fromCharCode(data[i]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue