I''m porting some code from PHP into Rails; is there an equivalent of the PHP "stripcslashes" function in Ruby/Rails? http://us.php.net/stripcslashes -- 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 -~----------~----~----~----~------~----~------~--~---
On Jul 21, 2007, at 11:51 , Ben Knight wrote:> I''m porting some code from PHP into Rails; is there an equivalent > of the > PHP "stripcslashes" function in Ruby/Rails?What are you trying to accomplish with stripslashes? (I.e., what are you trying to use stripslashes for?) There may be a better way to accomplish what you''re trying to do. The reason I ask is that I''ve often seen stripslashes used when interpolating into an SQL query string, which is a great way to set yourself up for SQL injection. A safe way to do the same thing is using bind variables. For (a simple, better-accomplished-via-a-straight-up-find) example: sql = "SELECT * FROM foo WHERE foo_id = :foo_id" id = 3 Foo.find_by_sql([sql, {:foo_id => id}]) If you''re not interpolating into an SQL query string please ignore the above. I still think there''s a better way to do whatever you''re trying to accomplish with stripslashes. What are you trying to do? Hoping to help, Michael Glaesemann grzm seespotcode net --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Michael Glaesemann wrote:>> PHP "stripcslashes" function in Ruby/Rails? > > What are you trying to accomplish with stripslashes? (I.e., what areNote he said "stripcslashes" not "stripslashes". Different function. Eric --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Jul 21, 2007, at 12:55 , Eric Anderson wrote:> Michael Glaesemann wrote: >>> PHP "stripcslashes" function in Ruby/Rails? >> >> What are you trying to accomplish with stripslashes? (I.e., what are > > Note he said "stripcslashes" not "stripslashes". Different function.Good eye :) I missed that. Thanks, Eric. Request for application still stands, however. Michael Glaesemann grzm seespotcode net --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ben Knight wrote:> I''m porting some code from PHP into Rails; is there an equivalent of the > PHP "stripcslashes" function in Ruby/Rails? > > http://us.php.net/stripcslashesWell, It shouldn''t be hard :) Does the function just strip the slashes as below? Example \''nice\nguy\'' Result ''nice guy'' -- 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 -~----------~----~----~----~------~----~------~--~---
Hi, Jamal. I ended up using the delete function and you are right, it wasn''t hard :-) I wasn''t sure what the PHP function did exactly since I''m not a PHP developer but I ended up doing something like this and I believe it duplicates the PHP functionality: data.delete(''\r'').delete(''\n'').delete("\\") Jamal Soueidan wrote:> Well, It shouldn''t be hard :) > > Does the function just strip the slashes as below? > > Example > \''nice\nguy\'' > > Result > ''nice > guy''-- 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 -~----------~----~----~----~------~----~------~--~---
Ben Knight wrote:> Hi, Jamal. I ended up using the delete function and you are right, it > wasn''t hard :-) I wasn''t sure what the PHP function did exactly since > I''m not a PHP developer but I ended up doing something like this and I > believe it duplicates the PHP functionality: > > data.delete(''\r'').delete(''\n'').delete("\\") > > > Jamal Soueidan wrote: >> Well, It shouldn''t be hard :) >> >> Does the function just strip the slashes as below? >> >> Example >> \''nice\nguy\'' >> >> Result >> ''nice >> guy''If you just want to remove them, then you can use the delete function as you did. But you must understand that \n is like <br /> \\ is like \ \t is like TABKEY So you might want to think about that :) -- 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 -~----------~----~----~----~------~----~------~--~---
Hi, Jamal. I had to remove the first 2 delete calls since it was deleting all my "r" and "n" characters (e.g. notes became otes). I wasn''t sure how I could delete carriage-returns and new-lines instead of r and n characters.? For example, I tried both, \\r and \r with delete. Anyway, for now, I think just removing back-slashes will do the trick based on this description of the PHP function (and what I think, is our requirement :-) http://us.php.net/stripcslashes Thanks for all your help! Jamal Soueidan wrote:> > If you just want to remove them, then you can use the delete function as > you did. > > But you must understand that > > \n is like <br /> > \\ is like \ > \t is like TABKEY > > So you might want to think about that :)-- 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 -~----------~----~----~----~------~----~------~--~---