Permalink
Browse files

simple_format must not modify the source strings passed to it, confus…

…ing and trashes attribute dirty tracking
  • Loading branch information...
1 parent 87bbf48 commit 27c492015fb87f7f2977096f48a9d6181373679d @willbryant committed Oct 16, 2011
@@ -250,8 +250,7 @@ def word_wrap(text, *args)
# simple_format("Look ma! A class!", :class => 'description')
# # => "<p class='description'>Look ma! A class!</p>"
def simple_format(text, html_options={}, options={})
- text = text ? text.to_str : ''
- text = text.dup if text.frozen?
+ text = text ? text.to_str.dup : ''
start_tag = tag('p', html_options, true)
text.gsub!(/\r\n?/, "\n") # \r\n and \r -> \n
text.gsub!(/\n\n+/, "</p>\n\n#{start_tag}") # 2+ newline -> paragraph
@@ -52,6 +52,12 @@ def test_simple_format_should_not_be_html_safe_when_sanitize_option_is_false
assert !simple_format("<b> test with unsafe string </b><script>code!</script>", {}, :sanitize => false).html_safe?
end
+ def test_simple_format_does_not_modify_source
+ str = "This string object should not be modified"
+ assert_equal "<p>This string object should not be modified</p>", simple_format(str)
+ assert_equal "This string object should not be modified", str
+ end
+
def test_truncate_should_not_be_html_safe
assert !truncate("Hello World!", :length => 12).html_safe?
end

0 comments on commit 27c4920

Please sign in to comment.