title: Rails3 and safe nl2br !
body: <p>I have a system for the users to be able to post comments.</p>
  
  <p>The comments are grasped into a textarea.</p>
  
  <p>My problem is to format the comments with br tag to replace \n</p>
  
  <p>In fact, i could do something like that </p>
  
  <p><code>s.gsub(/\n/, '&lt;br /&gt;')</code></p>
  
  <p>But the xss protection including in rails escapes br tags.</p>
  
  <p>So i could do this </p>
  
  <p><code>s.gsub(/\n/, '&lt;br /&gt;').html_safe</code></p>
  
  <p>But then, all the tags are accepted even script.... causing a big security problem</p>
  
  <p>So my question is : how to format text with br safely ?</p>
  
  <p>Thanks</p>
  
  <p>EDIT:
  For now, i have add this</p>
  
  <pre><code>  def sanitaze
      self.gsub(/(&lt;.*?&gt;)/, '')
    end
  
    def nl2br
      self.sanitaze.gsub(/\n/, '&lt;br /&gt;').html_safe
    end
  </code></pre>