From 4773b9828705527f5c5795aa8c1577cd0c568570 Mon Sep 17 00:00:00 2001
From: Adam McCrea
Date: Wed, 20 Jan 2010 15:07:21 -0500
Subject: [PATCH 1/2] simple_format should not allow its output to be escaped
---
actionpack/lib/action_view/helpers/text_helper.rb | 1 +
actionpack/test/template/text_helper_test.rb | 8 ++++++--
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb
index 814d868..86f1e15 100644
--- a/actionpack/lib/action_view/helpers/text_helper.rb
+++ b/actionpack/lib/action_view/helpers/text_helper.rb
@@ -333,6 +333,7 @@ module ActionView
text.gsub!(/([^\n]\n)(?=[^\n])/, '\1
') # 1 newline -> br
text.insert 0, start_tag
text << "
"
+ raw(text)
end
# Turns all URLs and e-mail addresses into clickable links. The :link option
diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb
index 088c07b..8b60360 100644
--- a/actionpack/test/template/text_helper_test.rb
+++ b/actionpack/test/template/text_helper_test.rb
@@ -36,8 +36,12 @@ class TextHelperTest < ActionView::TestCase
text = "A\r\n \nB\n\n\r\n\t\nC\nD".freeze
assert_equal "A\n
\n
B
\n\n\t\n
C\n
D
", simple_format(text)
- assert_equal %q(This is a classy test
), simple_format("This is a classy test", :class => 'test')
- assert_equal %Q(para 1
\n\npara 2
), simple_format("para 1\n\npara 2", :class => 'test')
+ assert_equal %q(This is a classy test
), simple_format("This is a classy test", :class => 'test')
+ assert_equal %Q(para 1
\n\npara 2
), simple_format("para 1\n\npara 2", :class => 'test')
+ end
+
+ def test_simple_format_prevents_escaping_its_output
+ assert simple_format("A String").html_safe?
end
def test_truncate
--
1.6.4.2