I’m trying to decode URL both with query parameters and without query parameters. I’m using the Toolbox plugin to run js at the server side using the “server-script” element. I’m using the below code to decode URLs using js:
function extractAndCleanURL(input) {
const match = input.match(/(?<=\burl=)[^&]+/);
if (match) {
const encodedURL = match[0];
// Decode once or twice (some URLs are double encoded)
let decodedURL = decodeURIComponent(encodedURL);
try {
decodedURL = decodeURIComponent(decodedURL);
} catch (e) {
// If not double encoded, it's fine
}
const cleanURL = decodedURL
.replace(/([&?]form=[^&]*)(&|$)/, '')
.replace(/[&?]$/, '');
return cleanURL;
}
return null;
}
const input = 'data'; // data is the toolbox parameter for input values
const result = extractAndCleanURL(input);
console.log(result);
I can’t seem to get it to work in the plugin. The workflow process goes as follows shown in images
What am I doing wrong here? and how do I solve this?




