From dd8c912c6cb8f0b8e07664fcdd858777fc331ffd Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Sat, 10 Oct 2009 03:52:33 -0500 Subject: [PATCH] Update lib/node.rb Grab some fixes from html_scanner, and add few of our own. --- lib/node.rb | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/lib/node.rb b/lib/node.rb index b0d0eac6..6b5260e6 100644 --- a/lib/node.rb +++ b/lib/node.rb @@ -77,9 +77,9 @@ module XHTML #:nodoc: # Return a textual representation of the node. def to_s - s = "" + s = [] @children.each { |child| s << child.to_s } - s + s.join end # Return false (subclasses must override this to provide specific matching @@ -150,13 +150,19 @@ module XHTML #:nodoc: end if scanner.skip(/!\[CDATA\[/) - scanner.scan_until(/\]\]>/) + unless scanner.skip_until(/\]\]>/) + if strict + raise "expected ]]> (got #{scanner.rest.inspect} for #{content})" + else + scanner.skip_until(/\Z/) + end + end + return CDATA.new(parent, line, pos, scanner.pre_match.gsub(/\/]+/) end @@ -265,7 +272,7 @@ module XHTML #:nodoc: # itself. class CDATA < Text #:nodoc: def to_s - "" + "" end end @@ -309,22 +316,20 @@ module XHTML #:nodoc: # Returns a textual representation of the node def to_s - s = '' if @closing == :close - s = "" unless self.childless? + "" unless self.childless? else - s = "<#{@name}" - atlist = @attributes.sort - atlist.each do |att| - s << " #{att[0]}" - s << "='#{att[1]}'" if String === att[1] + s = ["<#{@name}"] + @attributes.sort.each do |k,v| + s << " #{k}" + s << "='#{v}'" if String === v end s << "/" if (@children.empty? && @closing == :self) or self.childless? s << ">" @children.each { |child| s << child.to_s } - s << "" if @closing != :self && !@closing.nil? && !@children.empty? + s << "" if @closing != :self && !@closing.nil? && !@children.empty? + s.join end - s end # If either the node or any of its children meet the given conditions, the