Forum: Ruby on Rails PHP "stripclashes" equivalent in Ruby/Rails?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ben K. (Guest)
on 2007-07-21 20:51
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
Jamal S. (Guest)
on 2007-07-22 12:41
Ben K. 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/stripcslashes

Well, It shouldn't be hard :)

Does the function just strip the slashes as below?

Example
\'nice\nguy\'

Result
'nice
guy'
Ben K. (Guest)
on 2007-07-22 20:17
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 S. wrote:
> Well, It shouldn't be hard :)
>
> Does the function just strip the slashes as below?
>
> Example
> \'nice\nguy\'
>
> Result
> 'nice
> guy'
Jamal S. (Guest)
on 2007-07-22 21:11
Ben K. 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 S. 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 :)
Ben K. (Guest)
on 2007-07-22 23:08
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 S. 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 :)
Michael G. (Guest)
on 2007-07-26 02:46
(Received via mailing list)
On Jul 21, 2007, at 11:51 , Ben K. 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 G.
grzm seespotcode net
Michael G. (Guest)
on 2007-09-26 01:09
(Received via mailing list)
On Jul 21, 2007, at 12:55 , Eric A. wrote:

> Michael G. 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 G.
grzm seespotcode net
Eric A. (Guest)
on 2007-09-26 01:09
(Received via mailing list)
Michael G. 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.

Eric
This topic is locked and can not be replied to.