Permalink
Browse files

Add test and behavior for stripping all content from a string

  • Loading branch information...
1 parent f5fba86 commit 87dc3ffc711bfa6555ed5e26898a30a9bd051991 @brynary committed Jan 6, 2009
Showing with 7 additions and 1 deletion.
  1. +3 −1 lib/dryopteris/sanitize.rb
  2. +4 −0 test/test_strip_tags.rb
@@ -13,7 +13,9 @@ 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)
- doc.at("/html/body").inner_text
+ body_element = doc.at("/html/body")
+ return "" if body_element.nil?
+ body_element.inner_text
end
def sanitize(string_or_io, encoding=nil)
View
@@ -10,6 +10,10 @@ def test_empty_string
assert_equal Dryopteris.strip_tags(""), ""
end
+ def test_return_empty_string_when_nothing_left
+ assert_equal "", Dryopteris.strip_tags('<script>test</script>')
+ end
+
def test_removal_of_all_tags
html = <<-HTML
What's up <strong>doc</strong>?

0 comments on commit 87dc3ff

Please sign in to comment.