Damaris Fuentes
2006-Dec-20 23:40 UTC
Scaping quotes and backslashes (I hope you understand my pro
Hi you all, I have a weird problem escaping characters. The user types in a text area the following: <a href="javascript: void(0);" class="defns" onmouseover="coolTip(''<a href=\''#\''>Appears as secondary character in...</a>'', STICKY,MOUSEOFF, TEXTSIZE, ''1.5em'', FGCOLOR,''rgb(224,244,181)'');" onmouseout="nd();">Hello</a> When the page is rendered with the .to_html of RedCloth this works. (I''m using a Javscript code called CoolTip, that, when the mouse is over a word or words with this javascript, a tip appears. In this tip, a link can be written. The whole sentence about is the called to the javascript, but this is not important) I don''t want the user to type this stuff. So, I write that in rails, in a string: semantic_link = ''<a href="javascript: void(0);" class="defns" onmouseover="coolTip(\''<a href=\\\''#\\\'' >Appears as secondary character in...</a>\'', STICKY, MOUSEOFF, TEXTSIZE, \''1.5em\'', FGCOLOR,\''rgb(224,244,181)\'');" onmouseout="nd();">Hello</a>'' But this does not work; what rails renders is a mess. Am I doing something wrong escaping the rare characters? Cause the code at the very beginning does work, so the problem isn''t RedCloth or the javascript call... Thanks :( -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Andrew Roth
2006-Dec-21 04:30 UTC
Re: Scaping quotes and backslashes (I hope you understand my pro
Can you maybe boil it down to a smaller example? The only thing I can think of is maybe it''s un-escaping the characters too many times, or not enough times. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Damaris Fuentes
2006-Dec-22 13:43 UTC
Re: Scaping quotes and backslashes (I hope you understand my
Andrew Roth wrote:> Can you maybe boil it down to a smaller example?Yes; I was kind of desperate and I just threw the whole stuff :D I have to write this code, for a Javscript function: onmouseover="coolTip(''<a href=\''/wiki/show_appears?value=Fidel+Castro&name=primaryCharacter\''>Appears...</a>'', STICKY,MOUSEOFF);" If I write this in a text area, as it is, and then I render the page, everything is ok. However, this whoole string will be given as a variable in my app. So I tried with this: semantic_link = ''onmouseover="coolTip(\''<a href=\\\''/wiki/show_appears?value=Fidel+Castro&name=primaryCharacter\\\'' >Appears...</a>\'', STICKY, MOUSEOFF);"'' The problem is in the a href=\\\''/wiki/ ... If i put 2 backslashes (to return a backslash), and another one to return the '', what rails render is a dot. I ve tried with other combinations but... they didn''t work! How can I do it? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Paul Corcoran
2006-Dec-22 21:53 UTC
Re: Scaping quotes and backslashes (I hope you understand my
If I hardcode the anchor tag in my rhtml file as follows it works fine for me. I did have to dispense with the \\ though. However, I get the impression you were not hardcoding this in your view. If your still having trouble with it, post your controller and view code. <a href="javascript: void(0);" class="defns" onmouseover="coolTip(''<a href=\''/wiki/show_appears?value=Fidel+Castro&name=primaryCharacter\'' >Appears...</a>'',STICKY, MOUSEOFF);" onmouseout="nd();">Hello</a> -Paul --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Damaris Fuentes
2006-Dec-22 22:27 UTC
Re: Scaping quotes and backslashes (I hope you understand my
Paul Corcoran wrote:> If I hardcode the anchor tag in my rhtml file as follows it works fine > for me. I did have to dispense with the \\ though. However, I get the > impression you were not hardcoding this in your view. If your still > having trouble with it, post your controller and view code. > > <a href="javascript: void(0);" class="defns" > onmouseover="coolTip(''<a > href=\''/wiki/show_appears?value=Fidel+Castro&name=primaryCharacter\'' > >Appears...</a>'',STICKY, MOUSEOFF);" > onmouseout="nd();">Hello</a> > > -PaulThis anchor tag also works for me if I write it as it is in a rhtml file. But I have to generate it from the application. So I have to write the anchor inside a string (cause the link /wiki/show... will change depending on several things). My problem is having the anchor tag inside a string variable in rails. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Paul Corcoran
2006-Dec-23 04:26 UTC
Re: Scaping quotes and backslashes (I hope you understand my
Ok, I understand you need to change it programmatically. I added the \\ back in, put it in a string assigned to an instance variable and did a simple render in the view. It seems to work just fine for me. Here is the string in my controller: @testvar = ''<a href="javascript: void(0);" class="defns" onmouseover="coolTip(\''<a href=\\\''/wiki/show_appears?value=Fidel+Castro&name=primaryCharacter\\\'' >Appears...</a>\'',STICKY, MOUSEOFF);" onmouseout="nd();">Hello</a>'' Here is the rhtml code: <%= @testvar %> And here is the html as it appears in the browser when I do view source: <a href="javascript: void(0);" class="defns" onmouseover="coolTip(''<a href=\''/wiki/show_appears?value=Fidel+Castro&name=primaryCharacter\'' >Appears...</a>'',STICKY, MOUSEOFF);" onmouseout="nd();">Hello</a> By the way I am using Firefox 1.0.5.9 and IE 6. -Paul --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Damaris Fuentes
2006-Dec-23 13:37 UTC
Re: Scaping quotes and backslashes (I hope you understand my
Paul Corcoran wrote:> Ok, I understand you need to change it programmatically. I added the \\ > back in, put it in a string assigned to an instance variable and did a > simple render in the view. It seems to work just fine for me. Here is > the string in my controller: > > @testvar = ''<a href="javascript: void(0);" class="defns" > onmouseover="coolTip(\''<a > href=\\\''/wiki/show_appears?value=Fidel+Castro&name=primaryCharacter\\\'' > >Appears...</a>\'',STICKY, MOUSEOFF);" > onmouseout="nd();">Hello</a>'' > > Here is the rhtml code: > > <%= @testvar %> > > And here is the html as it appears in the browser when I do view > source: > > <a href="javascript: void(0);" class="defns" > onmouseover="coolTip(''<a > href=\''/wiki/show_appears?value=Fidel+Castro&name=primaryCharacter\'' > >Appears...</a>'',STICKY, MOUSEOFF);" > onmouseout="nd();">Hello</a> > > By the way I am using Firefox 1.0.5.9 and IE 6. > > -PaulNo, sorry :( It does not work for me. The three backslashes turned into a dot. Dunno why :( I''m not using RedCloth at all, I just throw the variable as you in the rhtml. Can it be the Rails version? I''m using rails 1.1.4 :( Thanks a lot -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Damaris Fuentes
2006-Dec-23 14:46 UTC
Re: Scaping quotes and backslashes (I hope you understand my
I''m narrowing the error... I have test the variable var = ''\\\'''' and when this var is rendered in an rhtml, it works fine, as you''ve told me. The render symbols are \'' Buuuuut, what i have to do is programatically substitute a pattern for the link tag. So when I do: semantic_body.gsub!(''test'',var)... this does not work!! It adds a dot. Why this behaviour???? (in fact, it not only returns a dot, but the following paragrpahs are mixed in a mess..living the dot a paragraph away instead!! dunno) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Paul Corcoran
2006-Dec-23 14:55 UTC
Re: Scaping quotes and backslashes (I hope you understand my
I was using rails v1.1.2 but I just upgraded to v1.1.6 and it still works fine for me. I am using Ruby v1.8.4 on a Windows XP box. I guess at this point I would check the development.log to see if there is something in there that might give you a clue. I suppose it''s also possible a plug-in might be causing the problem Otherwise, I think your only recourse is to rebuild the environment by installing a clean version of ruby on rails. Don''t install any plug-ins and give it another shot. -Paul PS:<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Paul Corcoran
2006-Dec-23 16:12 UTC
Re: Scaping quotes and backslashes (I hope you understand my
Damaris - if you can post an example of working code that fails I think we can figure this out. Show me a real code fragment, something I can recreate on my end. Thanks, Paul --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Damaris Fuentes
2006-Dec-23 20:15 UTC
Re: Scaping quotes and backslashes (I hope you understand my
Ok, instead of giving my rails stuff code, try this in a simple Ruby file: var = ''\\\'''' varTest1 = ''hola'' print "ARG" + var print "ERG" + varTest1.gsub!(''hola'', var) The two "prints" should return the same, should''n they? But they don''t :( The first "print" returns my so lovely \'' but the second returns nothing. Could you please try if you obtain the same results? Cause if I have to uninstall everything... pfff, I''m gonna die :((( (I have ruby version 1.8.2) Thanks for your help, really :( -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Paul Corcoran
2006-Dec-23 21:40 UTC
Re: Scaping quotes and backslashes (I hope you understand my
It seems we need to add another set of double backslashes to get the desired results. I don''t understand this as the documentation says that on a single quoted string that a double backslash converts to a single backslash. puts "ERG" + varTest1.gsub!(''hola'', ''\\\\\'''') --> ERG\'' -Paul --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Damaris Fuentes
2006-Dec-24 00:45 UTC
Re: Scaping quotes and backslashes (I hope you understand my
Paul Corcoran wrote:> It seems we need to add another set of double backslashes to get the > desired results. I don''t understand this as the documentation says that > on a single quoted string that a double backslash converts to a single > backslash. > > puts "ERG" + varTest1.gsub!(''hola'', ''\\\\\'''') --> ERG\'' > > -PaulWow!! It works!! You''ve saved my life!!!!!!!!!!!!!!!!!!!! Thank you really much. I don''t understand either, cause all works fine according to the documentation but the "gsub" function. Thanks again, thanks for your help, and patience. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Paul Corcoran
2006-Dec-24 01:09 UTC
Re: Scaping quotes and backslashes (I hope you understand my
Glad to see it fixed the problem. I''ve added this to my growing list of gotcha''s. :) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Damaris Fuentes wrote:> Paul Corcoran wrote: >> It seems we need to add another set of double backslashes to get the >> desired results. I don''t understand this as the documentation says that >> on a single quoted string that a double backslash converts to a single >> backslash. >> >> puts "ERG" + varTest1.gsub!(''hola'', ''\\\\\'''') --> ERG\'' >> >> -Paul > > Wow!! It works!! You''ve saved my life!!!!!!!!!!!!!!!!!!!! > Thank you really much. > > I don''t understand either, cause all works fine according to the > documentation but the "gsub" function. > > Thanks again, thanks for your help, and patience.Its because the string is going to the regexp replacement engine. If you do: a = ''\\1'' # that gives you a slash and a 1 in a string. however: b = ''blah'' b.gsub! /(l)a/, a b # => ''blh'', no slash 1 in sight. Thats because \[0-9] is used for the back-references. A (probably slower) solution, is to avoid this by using the block approach: b.gsub!(/(l)a/) { a } # => "b\\1h" -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---