I’ve got a strange issue with decoding an escaped javascript string.
Here is the test code, getting the escaped string from the data attribute doesn’t work it just gets printed out raw. The second example works fine.
var emailText = $('#emaildata').data('email-text');
var unescapedEmailText = decodeURIComponent(emailText);
alert(unescapedEmailText);
var emailText2 = "Blah blah edit blah foo\x27\x0a\x0a\x0a\x27\x27\x27";
var unescapedEmailText2 = decodeURIComponent(emailText2);
alert(unescapedEmailText2);
Here is a jsfiddle showing the broken functionality. http://jsfiddle.net/wnegH/2/
I’m sure i’m doing something daft, but what I can’t fathom out…
What you put inside the
data-email-textattribute is not a javascript string. So using\x27inside it, simply means the\x27string as-is and not the corresponding ASCII character.Here’s an example of how you could achieve the desired effect:
and then:
Obviously the string I have used in the
data-email-textattribute was obtained by invoking theencodeURIComponentfunction on the target string.