Not logged in. · Lost password · Register
Forum: Features request RSS
More advanced escaping
for XML and JavaScript
Tom W.M. #1
Member since Feb 2003 · 40 posts · Location: La Crosse, WI, USA
Group memberships: Members
Show profile · Link to this post
It would be really nice to have proper escaping of characters in XML and JavaScript.

For XML, using urlencoded=true, as suggested by the manual, is just silly.  All I want here is escaping of <, >, ", and & for putting strings in attribute nodes.  (Anywhere else, a CDATA block can be used.)  One should be able to enable this on any tag, with something like, "xmlescape=true."

For JavaScript (especially JSON notation), escape=true doesn't work properly, because it replaces a double quote/prime (") with &quot;, though some other characters are properly escaped.  Something like jsescape=true should escape ", \, and all of the control characters (\b, \f, \n, \r, \t).  Perhaps jsescape=unicode should do all of the above, but escape Unicode characters in the form \u#### as well.  (This would only be needed if a page isn't being sent as Unicode, which would cause Unicode-only JS strings to choke on non-ASCII characters.)  The problem with the current best bethod, urlencoded=true, is that decodeURIComponent() produces (fatal) errors on some non-ASCII characters, in my experience.  Even more annoyingly [the former problem can be bypassed by using the deprecated unescape() instead of decodeURIComponent()], urlencoded=true inserts plus signs (+) instead of spaces!  What's so wrong with a simple %20?  These same issues apply even more forcefully to XML, where postprocessing is not guranteed.

On a somewhat different note, it would be nice [though this is easily worked around with parseInt("##",10)] if there were a property, say, jslegal=true, that prevents BrowseAmp from writing out leading zeroes when a tag produces a number (e.g. <#SongLengthSec>).  The problem with the default behavior is that, in JavaScript, a number with a leading zero is interpreted as an octal.  Luckily, for 01, 02, etc., the numbers produced are equivalent; however, at, say, 09, the number is not a legal octal!  This produces a (fortunately, non-fatal) error in the JavaScript console for a number of skins.

Tom W.M.
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
This board is powered by the Unclassified NewsBoard software, 20150713-dev, © 2003-2015 by Yves Goergen
Page created in 147.5 ms (61.1 ms) · 37 database queries in 54.5 ms
Current time: 2018-02-24, 12:28:53 (UTC +00:00)