Skip to content
Browse files

Merge pull request #1749 from dmathieu/simple_format

Cherry pick changes to simple_format from master
  • Loading branch information...
2 parents b2efd2a + 0ee586d commit 6759e6730469805e40df8884cd6ba18fbfc681f7 @josevalim josevalim committed Jun 17, 2011
Showing with 4 additions and 5 deletions.
  1. +4 −5 actionpack/lib/action_view/helpers/text_helper.rb
View
9 actionpack/lib/action_view/helpers/text_helper.rb
@@ -255,16 +255,15 @@ def word_wrap(text, *args)
# simple_format("<span>I'm allowed!</span> It's true.", {}, :sanitize => false)
# # => "<p><span>I'm allowed!</span> It's true.</p>"
def simple_format(text, html_options={}, options={})
- text = text ? text.to_str : ''
- text = text.dup if text.frozen?
+ text = '' if text.nil?
start_tag = tag('p', html_options, true)
+ text = sanitize(text) unless options[:sanitize] == false
+ text = text.to_str
text.gsub!(/\r\n?/, "\n") # \r\n and \r -> \n
text.gsub!(/\n\n+/, "</p>\n\n#{start_tag}") # 2+ newline -> paragraph
text.gsub!(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
text.insert 0, start_tag
- text.concat("</p>")
- text = sanitize(text) unless options[:sanitize] == false
- text
+ text.html_safe.safe_concat("</p>")
end
# Creates a Cycle object whose _to_s_ method cycles through elements of an

0 comments on commit 6759e67

Please sign in to comment.
Something went wrong with that request. Please try again.