Permalink
Browse files

removing unnecessary xpath() lookups, fixing version-specific test

  • Loading branch information...
1 parent 0c3105b commit b97b5722682174318eeb6506145833a653af5b16 @flavorjones flavorjones committed Dec 5, 2008
Showing with 9 additions and 7 deletions.
  1. +8 −6 lib/dryopteris/sanitize.rb
  2. +1 −1 test/test_sanitizer.rb
View
@@ -13,23 +13,25 @@ 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.xpath("html/body/*").each do |node|
+ 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
- snippet = doc.xpath("html/body").first
- snippet.nil? ? "" : snippet.inner_html
+ body.inner_html
end
def sanitize(string_or_io, encoding=nil)
return nil if string_or_io.nil?
return "" if string_or_io.strip.size == 0
doc = Nokogiri::HTML.parse(string_or_io, nil, encoding)
- doc.xpath("html/body/*").each do |node|
+ body = doc.xpath("/html/body").first
+ return "" if body.nil?
+ body.children.each do |node|
traverse_conditionally_top_down(node, :sanitize_node)
end
- snippet = doc.xpath("html/body").first
- snippet.nil? ? "" : snippet.inner_html
+ body.inner_html
end
private
View
@@ -38,7 +38,7 @@ def check_sanitization(input, htmloutput, xhtmloutput, rexmloutput)
# xhtmloutput = htmloutput
# rexmloutput = "<image title='1'>foo &lt;bad&gt;bar&lt;/bad&gt; baz</image>"
if WhiteList::VOID_ELEMENTS.include?(tag_name)
- if Nokogiri::LIBXML_VERSION >= "2.6.16"
+ if Nokogiri::LIBXML_VERSION <= "2.6.16"
htmloutput = "<#{tag_name} title='1'/><p>foo &lt;bad&gt;bar&lt;/bad&gt; baz</p>"
else
htmloutput = "<#{tag_name} title='1'/>foo &lt;bad&gt;bar&lt;/bad&gt; baz"

0 comments on commit b97b572

Please sign in to comment.