mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-23 16:26:16 -04:00
added encode all chars for url encode
This commit is contained in:
parent
ba12ad8e7c
commit
c555e54dee
1 changed files with 94 additions and 62 deletions
|
@ -28,7 +28,12 @@ class URLEncode extends Operation {
|
|||
"name": "Encode all special chars",
|
||||
"type": "boolean",
|
||||
"value": false
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Encode all chars",
|
||||
"type": "boolean",
|
||||
"value": false
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -39,7 +44,19 @@ class URLEncode extends Operation {
|
|||
*/
|
||||
run(input, args) {
|
||||
const encodeAll = args[0];
|
||||
return encodeAll ? this.encodeAllChars(input) : encodeURI(input);
|
||||
const encodeAllEvery = args[1];
|
||||
return encodeAllEvery ? this.encodeAllEveryChars(input) : encodeAll ? this.encodeAllChars(input) : encodeURI(input);
|
||||
//return encodeAll ? this.encodeAllChars(input) : encodeURI(input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pads a string from the front to a given length with a given char
|
||||
*
|
||||
* @param {string} str
|
||||
* @returns {string}
|
||||
*/
|
||||
frontPad (str, length, char){
|
||||
return str.length >= length ? str : (char * (length - str.length)) + str;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,7 +80,22 @@ class URLEncode extends Operation {
|
|||
.replace(/~/g, "%7E");
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode ALL characters in URL including alphanumeric based on char codes
|
||||
*
|
||||
* @param {string} str
|
||||
* @returns {string}
|
||||
*/
|
||||
encodeAllEveryChars (str) {
|
||||
let encoded = "";
|
||||
for (var char of str) {
|
||||
encoded += "%" + this.frontPad(char.charCodeAt(0).toString(16).toUpperCase(), 2, "0")
|
||||
}
|
||||
return encoded;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
export default URLEncode;
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue