Skip to content

Commit

Permalink
Fixed textilize_without_paragraph and added tests for it. [#4792 stat…
Browse files Browse the repository at this point in the history
…e:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
rohitarondekar authored and josevalim committed Jun 8, 2010
1 parent a4eaa1f commit 67f411c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/helpers/text_helper.rb
Expand Up @@ -275,7 +275,7 @@ def textilize(text, *options)
# textilize_without_paragraph("Visit the Rails website "here":http://www.rubyonrails.org/.)
# # => "Visit the Rails website <a href="http://www.rubyonrails.org/">here</a>."
def textilize_without_paragraph(text, *options)
textiled = textilize(text, options)
textiled = textilize(text, *options)
if textiled[0..2] == "<p>" then textiled = textiled[3..-1] end
if textiled[-4..-1] == "</p>" then textiled = textiled[0..-5] end
return textiled
Expand Down
32 changes: 32 additions & 0 deletions actionpack/test/template/text_helper_test.rb
Expand Up @@ -693,5 +693,37 @@ def test_textilize_should_not_sanitize_safe_input
def test_textilize_with_hard_breaks
assert_equal("<p>This is one scary world.<br />\n True.</p>", textilize("This is one scary world.\n True."))
end

def test_textilize_without_paragraph_should_be_html_safe
textilize_without_paragraph("*This is Textile!* Rejoice!").html_safe?
end

def test_textilize_without_paragraph
assert_equal("<strong>This is Textile!</strong> Rejoice!", textilize_without_paragraph("*This is Textile!* Rejoice!"))
end

def test_textilize_without_paragraph_with_blank
assert_equal("", textilize_without_paragraph(""))
end

def test_textilize_without_paragraph_with_options
assert_equal("This is worded &lt;strong&gt;strongly&lt;/strong&gt;", textilize_without_paragraph("This is worded <strong>strongly</strong>", :filter_html))
end

def test_textilize_without_paragraph_should_sanitize_unsafe_input
assert_equal("This is worded <strong>strongly</strong>", textilize_without_paragraph("This is worded <strong>strongly</strong><script>code!</script>"))
end

def test_textilize_without_paragraph_should_not_sanitize_input_if_safe_option
assert_equal("This is worded <strong>strongly</strong><script>code!</script>", textilize_without_paragraph("This is worded <strong>strongly</strong><script>code!</script>", :safe))
end

def test_textilize_without_paragraph_should_not_sanitize_safe_input
assert_equal("This is worded <strong>strongly</strong><script>code!</script>", textilize_without_paragraph("This is worded <strong>strongly</strong><script>code!</script>".html_safe))
end

def test_textilize_without_paragraph_with_hard_breaks
assert_equal("This is one scary world.<br />\n True.", textilize_without_paragraph("This is one scary world.\n True."))
end
end
end

0 comments on commit 67f411c

Please sign in to comment.