Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old October 14th, 2008, 05:45 AM
Robert Mark Bram
Guest
 
Posts: n/a
Default Unescape escapeXML text

Hi All,

I have an application that is writing Javascript with JSP server side
code that uses escapeXML:

var someVar = "<c:out escapeXml="true" value="You'll never escape!"/
Quote:
>";
How to I unescape this? Using the unescape() function doesn't cut
it..
unescape("You'll never escape!");

Do I have to use regex to replace or is there some other way?

Thanks for any assistance!

Rob
:)
  #2  
Old October 14th, 2008, 09:35 AM
Bart Van der Donck
Guest
 
Posts: n/a
Default Re: Unescape escapeXML text

Robert Mark Bram wrote:
Quote:
I have an application that is writing Javascript with JSP server side
code that uses escapeXML:
>
var someVar = "<c:out escapeXml="true" value="You'll never escape!"/
Quote:
";
>
How to I unescape this? Using the unescape() function doesn't cut
it. unescape("You'll never escape!");
>
Do I have to use regex to replace or is there some other way?
var txt = 'apostrophe ' / double quote: " / '
+ ' s: s / è: è / Chinese sign: 新';

txt = txt.replace(/(&#)([0-9]{1,5})(;)/g,
function (a1, a2, a3, a4) {
return String.fromCharCode(a3);
}
);
alert(txt);

Hope this helps,

--
Bart
  #3  
Old October 15th, 2008, 12:15 AM
dhtml
Guest
 
Posts: n/a
Default Re: Unescape escapeXML text

Robert Mark Bram wrote:
Quote:
Hi All,
>
I have an application that is writing Javascript with JSP server side
code that uses escapeXML:
>
var someVar = "<c:out escapeXml="true" value="You'll never escape!"/
Quote:
>";
>
How to I unescape this? Using the unescape() function doesn't cut
it..
unescape("You'll never escape!");
>
Or could escape it differently.

If you are using struts you can use StringEscapeUtils.escapeJavaScript.

Would be really nice to have c:out handle that.

Fictitious example:
<c:out escapeJavaScript="true" value="You'll never escape!"/>

Garrett
Quote:
>
Rob
:)

--
comp.lang.javascript FAQ <URL: http://jibbering.com/faq/ >
  #4  
Old October 15th, 2008, 09:15 PM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
Default Re: Unescape escapeXML text

Robert Mark Bram wrote:
Quote:
I have an application that is writing Javascript with JSP server side
code that uses escapeXML:
>
var someVar = "<c:out escapeXml="true" value="You'll never escape!"/>";
*g*
Quote:
How to I unescape this?
Maybe

someVar = someVar.replace(/&lt;/g, "<").replace(/&gt;/g, ">"
.replace(/&amp;/g, "&");
Quote:
Using the unescape() function doesn't cut it..
unescape("You'll never escape!");
It is not supposed to. unescape() decodes (ASCII) percent-encoded strings.
It was primarily used to decode URI components, and is now deprecated in
favor of decodeURI() and decodeURIComponent(), which in addition can decode
UTF-8 percent encoding.
Quote:
Do I have to use regex to replace or is there some other way?
A regular expression like above would not help in your case because the
escaping of `"' needs to take place *before* you insert the value with JSP,
i.e. "on the server".

You do not need `escapeXml="true"' if you declare the content of the XHTML
`script' element CDATA, provided the string never contains `"', like
in your example:

<script type="text/javascript">
// <![CDATA[
...
]]>
</script>

But if the `<' and `>' are your only problems, you could as well move the
code to an external script file or simply use HTML instead.


PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
  #5  
Old October 16th, 2008, 01:55 AM
Robert Mark Bram
Guest
 
Posts: n/a
Default Re: Unescape escapeXML text

Thanks to all for the input!
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles