I think the following code will be convenient to have in prototype.js: Object.extend(String.prototype, { escapeJS: function() { var text = ""; for (var i = 0, len = this.length; i < len; i++) { var ch = this.charAt(i); switch (ch) { case ''\b'': text += "\\b" break; case ''\n'': text += "\\n" break; case ''\t'': text += "\\t" break; case ''\f'': text += "\\f" break; case ''\r'': text += "\\r" break; case ''\"'': text += "\\u0022" break; case ''\'''': text += "\\u0027" break; case ''\\'': text += "\\\\" break; default: text += ch; } } return text; } } ); --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Hey there, ''sounds very much (functionally speaking) like the ajax-branch version of String.inspect to me... http://dev.rubyonrails.org/browser/spinoffs/prototype/branches/ajax/src/string.js?rev=6210 -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Thank you for the link! On Mar 1, 11:14 am, Christophe Porteneuve <t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org> wrote:> Hey there, > > ''sounds very much (functionally speaking) like the ajax-branch version > of String.inspect to me... > > http://dev.rubyonrails.org/browser/spinoffs/prototype/branches/ajax/s... > > -- > Christophe Porteneuve a.k.a. TDD > "[They] did not know it was impossible, so they did it." --Mark Twain > Email: t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
I see "String.inspect" don''t escape quotes into unicode. This behaviour needs for the following example: <html> <SCRIPT LANGUAGE="JAVASCRIPT" SRC="prototype.js"></SCRIPT> <div id="myDiv"> empty </div> <script> function blabla(message) { var str = "<a href=''javascript:alert(\""+message+"\")''>Hello</a>"; $("myDiv").innerHTML = str; } blabla("He\"llo"); </script> </html> If you click on link "Hello" javascript errors occurs. Solution is escape quotes into unicode: blabla("He\\u0022llo"); The above javascript code solve this problem. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Hey there, sinnus-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org a écrit :> I see "String.inspect" don''t escape quotes into unicode. > This behaviour needs for the following example:Actually, escaping quotes the usual way (with a backslash) will be sufficient for your need, and this is what this String#inspect does. -- Christophe Porteneuve aka TDD tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
No. It''s not sufficient for the above example. You can repeat this example using String#inspect and you will get javascript error. On Mar 1, 4:03 pm, Christophe Porteneuve <t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org> wrote:> Hey there, > > sin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org a écrit : > > > I see "String.inspect" don''t escape quotes into unicode. > > This behaviour needs for the following example: > > Actually, escaping quotes the usual way (with a backslash) will be > sufficient for your need, and this is what this String#inspect does. > > -- > Christophe Porteneuve aka TDD > t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Hey there, sinnus-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org a écrit :> No. It''s not sufficient for the above example. > You can repeat this example using String#inspect and you will get > javascript error.That''s because inspect retains a backwards-compatible behavior which has it use single quotes (and therefore escape single quotes) by default, and use double quotes (therefore escaping them) if you pass it true. So the following line fixes your example: var src = "<a href=''javascript:alert(" + message.inspect(true) + ");''>Hello</a>"; I should add that I hope this code was just for example purposes. I mean, javascript: href''s... Yewh! :-) -- Christophe Porteneuve aka TDD tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Fine :) Try to out the following message: blabla("He\''\"llo"); --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Hey, sinnus-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org a écrit :> Try to out the following message: > blabla("He\''\"llo");Yes :-) Now, indeed, in that very particular regard, inspect can''t be enough and still be backward-compatible (and, more importantly, developer-useful, as the consumer of its output is the debugging developer). -- Christophe Porteneuve aka TDD tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---