aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/template/text_helper_test.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-05-26 13:44:30 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-05-26 13:57:15 -0300
commit4ce3b5d6fe6451a7e6951f366d3e3f9324f75fdb (patch)
tree1e563d2b04346e0894b3c1043e95bfb98373b4ef /actionpack/test/template/text_helper_test.rb
parent9c8132c7bb3224dd357df7246ac65b647a59806f (diff)
downloadrails-4ce3b5d6fe6451a7e6951f366d3e3f9324f75fdb.tar.gz
rails-4ce3b5d6fe6451a7e6951f366d3e3f9324f75fdb.tar.bz2
rails-4ce3b5d6fe6451a7e6951f366d3e3f9324f75fdb.zip
Test that the block used in truncate is escaped if it is not HTML safe
Refactoring the truncate method to not do a sort-circuit return
Diffstat (limited to 'actionpack/test/template/text_helper_test.rb')
-rw-r--r--actionpack/test/template/text_helper_test.rb23
1 files changed, 11 insertions, 12 deletions
diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb
index a7333a3af9..4b1c1ef78b 100644
--- a/actionpack/test/template/text_helper_test.rb
+++ b/actionpack/test/template/text_helper_test.rb
@@ -60,14 +60,14 @@ class TextHelperTest < ActionView::TestCase
simple_format(text)
assert_equal text_clone, text
end
-
+
def test_simple_format_does_not_modify_the_html_options_hash
options = { :class => "foobar"}
passed_options = options.dup
simple_format("some text", passed_options)
assert_equal options, passed_options
end
-
+
def test_simple_format_does_not_modify_the_options_hash
options = { :wrapper_tag => :div, :sanitize => false }
passed_options = options.dup
@@ -98,7 +98,7 @@ class TextHelperTest < ActionView::TestCase
assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...".force_encoding('UTF-8'),
truncate("\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244".force_encoding('UTF-8'), :length => 10)
end
-
+
def test_truncate_does_not_modify_the_options_hash
options = { :length => 10 }
passed_options = options.dup
@@ -111,12 +111,6 @@ class TextHelperTest < ActionView::TestCase
truncate("Here's a long test and I need a continue to read link", :length => 27) { link_to 'Continue', '#' }
end
- def test_truncate_should_not_mutate_the_options_hash
- options = { :length => 27 }
- truncate("Here's a long test and I need a continue to read link", options) { link_to 'Continue', '#' }
- assert_equal({ :length => 27 }, options)
- end
-
def test_truncate_should_be_html_safe
assert truncate("Hello World!", :length => 12).html_safe?
end
@@ -135,6 +129,11 @@ class TextHelperTest < ActionView::TestCase
truncate("<script>code!</script>Here's a long test and I need a continue to read link", :length => 27) { link_to 'Continue', '#' }
end
+ def test_truncate_with_block_should_escape_the_block
+ assert_equal "Here's a long test and I...&lt;script&gt;alert('foo');&lt;/script&gt;",
+ truncate("Here's a long test and I need a continue to read link", :length => 27) { "<script>alert('foo');</script>" }
+ end
+
def test_highlight_should_be_html_safe
assert highlight("This is a beautiful morning", "beautiful").html_safe?
end
@@ -224,7 +223,7 @@ class TextHelperTest < ActionView::TestCase
highlight("<div>abc div</div>", "div", :highlighter => '<b>\1</b>')
)
end
-
+
def test_highlight_does_not_modify_the_options_hash
options = { :highlighter => '<b>\1</b>', :sanitize => false }
passed_options = options.dup
@@ -277,7 +276,7 @@ class TextHelperTest < ActionView::TestCase
def test_excerpt_with_utf8
assert_equal("...\357\254\203ciency could not be...".force_encoding('UTF-8'), excerpt("That's why e\357\254\203ciency could not be helped".force_encoding('UTF-8'), 'could', :radius => 8))
end
-
+
def test_excerpt_does_not_modify_the_options_hash
options = { :omission => "[...]",:radius => 5 }
passed_options = options.dup
@@ -292,7 +291,7 @@ class TextHelperTest < ActionView::TestCase
def test_word_wrap_with_extra_newlines
assert_equal("my very very\nvery long\nstring\n\nwith another\nline", word_wrap("my very very very long string\n\nwith another line", :line_width => 15))
end
-
+
def test_word_wrap_does_not_modify_the_options_hash
options = { :line_width => 15 }
passed_options = options.dup