views:

73

answers:

1

I'm having a strange problem where a user can enter the following text

Test '<3'

and it outputs as

Test '<3>

On the output I'm using white_list, and the value stored in the database is:

'testing ''<3'''

What could be causing the output to think it's a tag of some sort and trying to close it (which is what it looks like to me).

Thanks!

+2  A: 

Special characters in Ruby such as &, < and @ can sometimes be misinterpreted. Try using the "h" method in .rhtml pages.

<strong><%= h("This is a quick Test'<3'.") %></strong>

Will output:

<strong>This is a quick Test'&lt;3'.</strong>

So your browser will interpret it as:

This is a quick Test'<3'.

(I'm still relatively new to Ruby so I'm open to correction!)

Barry Gallagher
What does `h` do?
Robert S.
`h` is an alias for the `html_escape` method: http://api.rubyonrails.org/classes/ERB/Util.html#M000337
Pesto
I was actually trying to escape it with h but I was on the wrong view, doh! Swapping it from white_list string to h string worked. Thanks for keeping me on my toes.
mwilliams
You're welcome!
Barry Gallagher