mirror of
https://github.com/gchq/CyberChef.git
synced 2024-11-16 08:58:30 +01:00
56 lines
1.3 KiB
JavaScript
56 lines
1.3 KiB
JavaScript
/**
|
|
* @author n1474335 [n1474335@gmail.com]
|
|
* @copyright Crown Copyright 2016
|
|
* @license Apache-2.0
|
|
*/
|
|
|
|
import Operation from "../Operation.mjs";
|
|
|
|
/**
|
|
* 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>";
|
|
this.infoURL = "https://wikipedia.org/wiki/Percent-encoding";
|
|
this.inputType = "string";
|
|
this.outputType = "string";
|
|
this.args = [];
|
|
this.checks = {
|
|
input: {
|
|
regex: [
|
|
{
|
|
match: ".*(?:%[\\da-f]{2}.*){4}",
|
|
flags: "i",
|
|
args: []
|
|
},
|
|
]
|
|
}
|
|
};
|
|
}
|
|
|
|
/**
|
|
* @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;
|