mirror of
https://github.com/gchq/CyberChef.git
synced 2025-06-16 11:15:00 -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
|
@ -4,12 +4,12 @@
|
||||||
* @license Apache-2.0
|
* @license Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Operation from "../Operation.mjs";
|
import Operation from "../Operation.mjs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URL Encode operation
|
* URL Encode operation
|
||||||
*/
|
*/
|
||||||
class URLEncode extends Operation {
|
class URLEncode extends Operation {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URLEncode constructor
|
* URLEncode constructor
|
||||||
|
@ -28,7 +28,12 @@ class URLEncode extends Operation {
|
||||||
"name": "Encode all special chars",
|
"name": "Encode all special chars",
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"value": false
|
"value": false
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
"name": "Encode all chars",
|
||||||
|
"type": "boolean",
|
||||||
|
"value": false
|
||||||
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +44,19 @@ class URLEncode extends Operation {
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
const encodeAll = args[0];
|
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");
|
.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;
|
export default URLEncode;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue