add toggle treating "+" as spaces in URL decode

This commit is contained in:
TheSavageTeddy 2022-11-26 23:57:52 +08:00
parent ba12ad8e7c
commit 2f0da26999

View file

@ -23,7 +23,13 @@ class URLDecode extends Operation {
this.infoURL = "https://wikipedia.org/wiki/Percent-encoding";
this.inputType = "string";
this.outputType = "string";
this.args = [];
this.args = [
{
"name": "Treat \"+\" as space",
"type": "boolean",
"value": false
},
];
this.checks = [
{
pattern: ".*(?:%[\\da-f]{2}.*){4}",
@ -39,7 +45,8 @@ class URLDecode extends Operation {
* @returns {string}
*/
run(input, args) {
const data = input.replace(/\+/g, "%20");
const plusIsSpace = args[0];
const data = plusIsSpace ? input.replace(/\+/g, "%20") : input;
try {
return decodeURIComponent(data);
} catch (err) {