Permalink
Browse files

Just parse isn't enough, because HTML fragments become XML::Documents

  • Loading branch information...
indirect committed Nov 19, 2011
1 parent 236f903 commit 21157342c968221dcd1f072c20d034945caf00fc
Showing with 11 additions and 6 deletions.
  1. +11 −6 lib/webrat/core/xml.rb
@@ -6,14 +6,19 @@ module XML #:nodoc:
def self.document(stringlike) #:nodoc:
return stringlike.dom if stringlike.respond_to?(:dom)

if Nokogiri::HTML::Document === stringlike
case stringlike
when Nokogiri::HTML::Document

This comment has been minimized.

@ntalbott

ntalbott Dec 29, 2011

Ruby case statements don't fall through, so this ends up returning nil if an HTML::Document is passed in.

This comment has been minimized.

@indirect

indirect Dec 29, 2011

Collaborator

whoops. thanks for pointing that out!

when Nokogiri::XML::NodeSet
stringlike
elsif Nokogiri::XML::NodeSet === stringlike
stringlike
elsif stringlike.respond_to?(:body)
Nokogiri.parse(stringlike.body.to_s)
else
Nokogiri.parse(stringlike.to_s)
stringlike = stringlike.body if stringlike.respond_to?(:body)
stringlike = stringlike.to_s

if stringlike =~ /\<\?xml/
Nokogiri::XML(stringlike)
else
Nokogiri::HTML(stringlike)
end
end
end

0 comments on commit 2115734

Please sign in to comment.