Permalink
Browse files

Switching to using inner_text for strip_tags

  • Loading branch information...
1 parent 951657b commit 188d44c12760bab8f2a8b8396d18add6fe95bf4e @brynary committed Jan 6, 2009
Showing with 11 additions and 6 deletions.
  1. +1 −6 lib/dryopteris/sanitize.rb
  2. +10 −0 test/test_strip_tags.rb
@@ -13,12 +13,7 @@ def strip_tags(string_or_io, encoding=nil)
return "" if string_or_io.strip.size == 0
doc = Nokogiri::HTML.parse(string_or_io, nil, encoding)
- body = doc.xpath("/html/body").first
- return "" if body.nil?
- body.children.each do |node|
- traverse_conditionally_top_down(node, :remove_tags_from_node)
- end
- body.inner_html
+ doc.at("/html/body").inner_text
end
def sanitize(string_or_io, encoding=nil)
View
@@ -18,4 +18,14 @@ def test_removal_of_all_tags
assert_equal "What's up doc?".strip, stripped.strip
end
+ def test_dont_remove_whitespace
+ html = "Foo\nBar"
+ assert_equal html, Dryopteris.strip_tags(html)
+ end
+
+ def test_dont_remove_whitespace_between_tags
+ html = "<p>Foo</p>\n<p>Bar</p>"
+ assert_equal "Foo\nBar", Dryopteris.strip_tags(html)
+ end
+
end

0 comments on commit 188d44c

Please sign in to comment.