This is one that I got stuck on for a while..., I was serializing arbitrary objects and sending them across the wire, comments in methods, quotes, all kinds of stuff was screwing it up. It would seem like escaping everything would work, but I couldn't make it work.
So I wrote this:
BridgeTalkEncode = function( txt ) {
txt = encodeURIComponent( txt );
txt = txt.replace( /\r/, "%0d" );
txt = txt.replace( /\n/, "%0a" );
txt = txt.replace( /\\/, "%5c" );
txt = txt.replace(/'/g, "%27");
return txt.replace(/"/g, "%22");
}
You can decode it with decodeURI on the destination
For example, this works:
function mytest() {
var bt = new BridgeTalk ();
var theScript = "alert( decodeURI( 'Hello%0AWorld') );";
bt.target = 'photoshop';
bt.body = theScript;
bt.send();
}
If the scriptlet were restructured a little, you could call BridgeTalkEncode( msg ) on a string with the \n in it, and it would convert the \n to %0A for you (along with any other trouble-making characters).
Bob
Adobe WAS Scripting