So I'm trying to decode this string %21%22%23%C2%A4%25%26%2F to !"#¤%&/ inside my confirm so it doesn't say the encoded string in the confirm, but the actual string. But how can I do this?
I tried something like this, but it doesn't work.
...
if(confirm('Are you sure you want to removed the JQL: ' + decodeStr(encoded_string_value))){
...
}
function decodeStr(strVal) {
var decodeStr = '';
if(strVal && typeof strVal === 'string') {
// strip script/html tags
decodeStr = strVal.replace(/<script[^>]*>([\S\s]*?)<\/script>/gmi, '');
decodeStr = decodeStr.replace(/<\/?\w(?:[^"'>]|"[^"]*"|'[^']*')*>/gmi, '');
return decodeStr;
}
}
Is there another way of doing this?
Siddharth Rathod
6381 gold badge7 silver badges22 bronze badges
asked May 23, 2022 at 6:22
Mads Sander Høgstrup
7528 silver badges31 bronze badges
-
What is your actual string? or encoded string? Sample will helpHardik Shah– Hardik Shah2022年05月23日 06:28:30 +00:00Commented May 23, 2022 at 6:28
-
It's in the question @HardikShahMads Sander Høgstrup– Mads Sander Høgstrup2022年05月23日 07:01:51 +00:00Commented May 23, 2022 at 7:01
1 Answer 1
Did you try?
decodeURI(strVal)
or
decodeURIComponent(strVal)
answered May 23, 2022 at 6:26
Alexander
17.5k5 gold badges15 silver badges32 bronze badges
Sign up to request clarification or add additional context in comments.
3 Comments
Carsten Massmann
You will need to use
decodeURIComponent("%21%22%23%C2%A4%25%26%2F") // '!"#¤%&/'to get the wanted result.Alexander
@CarstenMassmann Good call
Mads Sander Høgstrup
Thanks! had only tried
decodeURI... decodeURIComponent works!lang-js