mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-23 08:16:17 -04:00
did encodeAllSpecialChars programmatically
This commit is contained in:
parent
4e13b074c5
commit
bd51fc05e3
1 changed files with 10 additions and 12 deletions
|
@ -65,18 +65,16 @@ class URLEncode extends Operation {
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
encodeAllSpecialChars (str) {
|
encodeAllSpecialChars (str) {
|
||||||
// TODO Do this programmatically
|
const specialChars = "!#'()*-._~";
|
||||||
return encodeURIComponent(str)
|
let encoded = "";
|
||||||
.replace(/!/g, "%21")
|
for (var char of str) {
|
||||||
.replace(/#/g, "%23")
|
if (encodeURIComponent(char) === char && specialChars.includes(char)){
|
||||||
.replace(/'/g, "%27")
|
encoded += "%" + this.frontPad(char.charCodeAt(0).toString(16).toUpperCase(), 2, "0");
|
||||||
.replace(/\(/g, "%28")
|
} else {
|
||||||
.replace(/\)/g, "%29")
|
encoded += encodeURIComponent(char);
|
||||||
.replace(/\*/g, "%2A")
|
}
|
||||||
.replace(/-/g, "%2D")
|
}
|
||||||
.replace(/\./g, "%2E")
|
return encoded;
|
||||||
.replace(/_/g, "%5F")
|
|
||||||
.replace(/~/g, "%7E");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue