On Wed, Feb 23, 2011 at 3:38 PM, mc_plectrum <[email protected]> wrote:

> Hi,
> In console i tried the following:
>
> ("t".html_safe + "t2").html_safe?
>  => true
>
> Why is it returning true?
>
>
> When you call .html_safe on the first String, it returns a SafeBuffer if it
is a safe string.

Now, when you add another string, and if it is a plain string and you have
not called .html_safe on it, the buffer escapes it first, then concatenates
it.

This is why, you are getting these results.

 to my mind:
> The concatenation of two Strings returns a new Object, which should
> only be html_safe, if both parts are html_safe, otherwise html_UNsafe.
>
> Yes, you are right. When you do String1 + String 2, it returns a new String
object. You can check it in irb, by calling .object_id on the String1,
String2 and String1+String2.

For more information on this, refer to
http://yehudakatz.com/2010/02/01/safebuffers-and-rails-3-0/.


>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Core" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-core?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to