0

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
2
  • What is your actual string? or encoded string? Sample will help Commented May 23, 2022 at 6:28
  • It's in the question @HardikShah Commented May 23, 2022 at 7:01

1 Answer 1

2

Did you try?

decodeURI(strVal)

or

decodeURIComponent(strVal)
answered May 23, 2022 at 6:26
Sign up to request clarification or add additional context in comments.

3 Comments

You will need to use decodeURIComponent("%21%22%23%C2%A4%25%26%2F") // '!"#¤%&/'to get the wanted result.
@CarstenMassmann Good call
Thanks! had only tried decodeURI... decodeURIComponent works!

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.