2018-05-14 23:15:28 +02:00
|
|
|
/**
|
|
|
|
* @author n1474335 [n1474335@gmail.com]
|
|
|
|
* @copyright Crown Copyright 2016
|
|
|
|
* @license Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2019-07-09 13:23:59 +02:00
|
|
|
import Operation from "../Operation.mjs";
|
2018-05-14 23:15:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* URL Decode operation
|
|
|
|
*/
|
|
|
|
class URLDecode extends Operation {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* URLDecode constructor
|
|
|
|
*/
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.name = "URL Decode";
|
|
|
|
this.module = "URL";
|
|
|
|
this.description = "Converts URI/URL percent-encoded characters back to their raw values.<br><br>e.g. <code>%3d</code> becomes <code>=</code>";
|
2018-08-21 20:07:13 +02:00
|
|
|
this.infoURL = "https://wikipedia.org/wiki/Percent-encoding";
|
2018-05-14 23:15:28 +02:00
|
|
|
this.inputType = "string";
|
|
|
|
this.outputType = "string";
|
|
|
|
this.args = [];
|
2020-03-24 12:06:37 +01:00
|
|
|
this.checks = [
|
|
|
|
{
|
|
|
|
pattern: ".*(?:%[\\da-f]{2}.*){4}",
|
|
|
|
flags: "i",
|
|
|
|
args: []
|
|
|
|
},
|
|
|
|
];
|
2018-05-14 23:15:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} input
|
|
|
|
* @param {Object[]} args
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
run(input, args) {
|
|
|
|
const data = input.replace(/\+/g, "%20");
|
|
|
|
try {
|
|
|
|
return decodeURIComponent(data);
|
|
|
|
} catch (err) {
|
|
|
|
return unescape(data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export default URLDecode;
|