From 1d5faf4a84f3aee6d5197f1a4f515ad307097ae3 Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Sat, 12 Apr 2008 18:56:02 -0500 Subject: [PATCH] Upgrade to latest REXML Sync with REXML svn. --- vendor/plugins/rexml/lib/rexml/attribute.rb | 2 + vendor/plugins/rexml/lib/rexml/document.rb | 203 +++++++++--------- .../rexml/lib/rexml/encodings/SHIFT-JIS.rb | 4 +- .../rexml/lib/rexml/formatters/transitive.rb | 4 +- .../rexml/lib/rexml/parsers/baseparser.rb | 2 +- vendor/plugins/rexml/lib/rexml/quickpath.rb | 9 +- vendor/plugins/rexml/lib/rexml/rexml.rb | 12 +- vendor/plugins/rexml/lib/rexml/text.rb | 9 +- 8 files changed, 124 insertions(+), 121 deletions(-) diff --git a/vendor/plugins/rexml/lib/rexml/attribute.rb b/vendor/plugins/rexml/lib/rexml/attribute.rb index 9dc0424d..4692a5b8 100644 --- a/vendor/plugins/rexml/lib/rexml/attribute.rb +++ b/vendor/plugins/rexml/lib/rexml/attribute.rb @@ -17,6 +17,8 @@ module REXML attr_writer :normalized PATTERN = /\s*(#{NAME_STR})\s*=\s*(["'])(.*?)\2/um + NEEDS_A_SECOND_CHECK = /(<|&((#{Entity::NAME});|(#0*((?:\d+)|(?:x[a-fA-F0-9]+)));)?)/um + # Constructor. # FIXME: The parser doesn't catch illegal characters in attributes # diff --git a/vendor/plugins/rexml/lib/rexml/document.rb b/vendor/plugins/rexml/lib/rexml/document.rb index f09aa2bc..fe605360 100644 --- a/vendor/plugins/rexml/lib/rexml/document.rb +++ b/vendor/plugins/rexml/lib/rexml/document.rb @@ -10,64 +10,65 @@ require "rexml/output" require "rexml/parsers/baseparser" require "rexml/parsers/streamparser" require "rexml/parsers/treeparser" +require "rexml/formatters/transitive" module REXML # Represents a full XML document, including PIs, a doctype, etc. A # Document has a single child that can be accessed by root(). # Note that if you want to have an XML declaration written for a document # you create, you must add one; REXML documents do not write a default - # declaration for you. See |DECLARATION| and |write|. - class Document < Element - # A convenient default XML declaration. If you want an XML declaration, - # the easiest way to add one is mydoc << Document::DECLARATION - # +DEPRECATED+ - # Use: mydoc << XMLDecl.default - DECLARATION = XMLDecl.default + # declaration for you. See |DECLARATION| and |write|. + class Document < Element + # A convenient default XML declaration. If you want an XML declaration, + # the easiest way to add one is mydoc << Document::DECLARATION + # +DEPRECATED+ + # Use: mydoc << XMLDecl.default + DECLARATION = XMLDecl.default - # Constructor - # @param source if supplied, must be a Document, String, or IO. - # Documents have their context and Element attributes cloned. - # Strings are expected to be valid XML documents. IOs are expected - # to be sources of valid XML documents. - # @param context if supplied, contains the context of the document; - # this should be a Hash. - def initialize( source = nil, context = {} ) - super() - @context = context - return if source.nil? - if source.kind_of? Document - @context = source.context - super source - else - build( source ) - end - end + # Constructor + # @param source if supplied, must be a Document, String, or IO. + # Documents have their context and Element attributes cloned. + # Strings are expected to be valid XML documents. IOs are expected + # to be sources of valid XML documents. + # @param context if supplied, contains the context of the document; + # this should be a Hash. + def initialize( source = nil, context = {} ) + super() + @context = context + return if source.nil? + if source.kind_of? Document + @context = source.context + super source + else + build( source ) + end + end def node_type :document end - # Should be obvious - def clone - Document.new self - end + # Should be obvious + def clone + Document.new self + end - # According to the XML spec, a root node has no expanded name - def expanded_name - '' - #d = doc_type - #d ? d.name : "UNDEFINED" - end + # According to the XML spec, a root node has no expanded name + def expanded_name + '' + #d = doc_type + #d ? d.name : "UNDEFINED" + end - alias :name :expanded_name + alias :name :expanded_name - # We override this, because XMLDecls and DocTypes must go at the start - # of the document - def add( child ) - if child.kind_of? XMLDecl - @children.unshift child + # We override this, because XMLDecls and DocTypes must go at the start + # of the document + def add( child ) + if child.kind_of? XMLDecl + @children.unshift child child.parent = self - elsif child.kind_of? DocType + elsif child.kind_of? DocType # Find first Element or DocType node and insert the decl right # before it. If there is no such node, just insert the child at the # end. If there is a child and it is an DocType, then replace it. @@ -85,60 +86,60 @@ module REXML else # Insert at end of list @children[insert_before_index] = child end - child.parent = self - else - rv = super - raise "attempted adding second root element to document" if @elements.size > 1 - rv - end - end - alias :<< :add + child.parent = self + else + rv = super + raise "attempted adding second root element to document" if @elements.size > 1 + rv + end + end + alias :<< :add - def add_element(arg=nil, arg2=nil) - rv = super - raise "attempted adding second root element to document" if @elements.size > 1 - rv - end + def add_element(arg=nil, arg2=nil) + rv = super + raise "attempted adding second root element to document" if @elements.size > 1 + rv + end - # @return the root Element of the document, or nil if this document - # has no children. - def root + # @return the root Element of the document, or nil if this document + # has no children. + def root elements[1] #self #@children.find { |item| item.kind_of? Element } - end + end - # @return the DocType child of the document, if one exists, - # and nil otherwise. - def doctype - @children.find { |item| item.kind_of? DocType } - end + # @return the DocType child of the document, if one exists, + # and nil otherwise. + def doctype + @children.find { |item| item.kind_of? DocType } + end - # @return the XMLDecl of this document; if no XMLDecl has been - # set, the default declaration is returned. - def xml_decl - rv = @children[0] + # @return the XMLDecl of this document; if no XMLDecl has been + # set, the default declaration is returned. + def xml_decl + rv = @children[0] return rv if rv.kind_of? XMLDecl rv = @children.unshift(XMLDecl.default)[0] - end + end - # @return the XMLDecl version of this document as a String. - # If no XMLDecl has been set, returns the default version. - def version - xml_decl().version - end + # @return the XMLDecl version of this document as a String. + # If no XMLDecl has been set, returns the default version. + def version + xml_decl().version + end - # @return the XMLDecl encoding of this document as a String. - # If no XMLDecl has been set, returns the default encoding. - def encoding - xml_decl().encoding - end + # @return the XMLDecl encoding of this document as a String. + # If no XMLDecl has been set, returns the default encoding. + def encoding + xml_decl().encoding + end - # @return the XMLDecl standalone value of this document as a String. - # If no XMLDecl has been set, returns the default setting. - def stand_alone? - xml_decl().stand_alone? - end + # @return the XMLDecl standalone value of this document as a String. + # If no XMLDecl has been set, returns the default setting. + def stand_alone? + xml_decl().stand_alone? + end # Write the XML tree out, optionally with indent. This writes out the # entire XML document, including XML declarations, doctype declarations, @@ -184,25 +185,25 @@ module REXML output = Output.new( output, xml_decl.encoding ) end formatter = if indent > -1 - if trans - REXML::Formatters::Transitive.new( indent, ie_hack ) - else - REXML::Formatters::Pretty.new( indent, ie_hack ) - end - else - REXML::Formatters::Default.new( ie_hack ) - end - formatter.write( self, output ) + if transitive + REXML::Formatters::Transitive.new( indent, ie_hack ) + else + REXML::Formatters::Pretty.new( indent, ie_hack ) end + else + REXML::Formatters::Default.new( ie_hack ) + end + formatter.write( self, output ) + end - def Document::parse_stream( source, listener ) - Parsers::StreamParser.new( source, listener ).parse - end - - private - def build( source ) - Parsers::TreeParser.new( source, self ).parse - end + def Document::parse_stream( source, listener ) + Parsers::StreamParser.new( source, listener ).parse end + + private + def build( source ) + Parsers::TreeParser.new( source, self ).parse + end + end end diff --git a/vendor/plugins/rexml/lib/rexml/encodings/SHIFT-JIS.rb b/vendor/plugins/rexml/lib/rexml/encodings/SHIFT-JIS.rb index 93c7877a..9e0f4af2 100644 --- a/vendor/plugins/rexml/lib/rexml/encodings/SHIFT-JIS.rb +++ b/vendor/plugins/rexml/lib/rexml/encodings/SHIFT-JIS.rb @@ -13,8 +13,8 @@ module REXML rescue LoadError require 'nkf' - SJISTOU8 = '-Swm0' - U8TOSJIS = '-Wsm0' + SJISTOU8 = '-Swm0x' + U8TOSJIS = '-Wsm0x' def decode_sjis(str) NKF.nkf(SJISTOU8, str) diff --git a/vendor/plugins/rexml/lib/rexml/formatters/transitive.rb b/vendor/plugins/rexml/lib/rexml/formatters/transitive.rb index 1d80f21f..6d92aa63 100644 --- a/vendor/plugins/rexml/lib/rexml/formatters/transitive.rb +++ b/vendor/plugins/rexml/lib/rexml/formatters/transitive.rb @@ -12,8 +12,9 @@ module REXML # formatted. Since this formatter does not alter whitespace nodes, the # results of formatting already formatted XML will be odd. class Transitive < Default - def initialize( indentation=2 ) + def initialize( indentation=2, ie_hack=false ) @indentation = indentation + @ie_hack = ie_hack @level = 0 end @@ -29,6 +30,7 @@ module REXML output << "\n" output << ' '*@level if node.children.empty? + output << " " if @ie_hack output << "/" else output << ">" diff --git a/vendor/plugins/rexml/lib/rexml/parsers/baseparser.rb b/vendor/plugins/rexml/lib/rexml/parsers/baseparser.rb index 85f2c4e4..162d029a 100644 --- a/vendor/plugins/rexml/lib/rexml/parsers/baseparser.rb +++ b/vendor/plugins/rexml/lib/rexml/parsers/baseparser.rb @@ -482,7 +482,7 @@ module REXML rv.gsub!( /\r\n?/, "\n" ) matches = rv.scan( REFERENCE_RE ) return rv if matches.size == 0 - rv.gsub!( /�*((?:\d+)|(?:x[a-fA-F0-9]+));/ ) {|m| + rv.gsub!( /�*((?:\d+)|(?:x[a-fA-F0-9]+));/ ) { m=$1 m = "0#{m}" if m[0] == ?x [Integer(m)].pack('U*') diff --git a/vendor/plugins/rexml/lib/rexml/quickpath.rb b/vendor/plugins/rexml/lib/rexml/quickpath.rb index c099db85..cdf4c530 100644 --- a/vendor/plugins/rexml/lib/rexml/quickpath.rb +++ b/vendor/plugins/rexml/lib/rexml/quickpath.rb @@ -170,15 +170,12 @@ module REXML rest = path[ind+1..-1] # have to change 'a [=<>] b [=<>] c' into 'a [=<>] b and b [=<>] c' - predicate.gsub!( /([^\s(and)(or)<>=]+)\s*([<>=])\s*([^\s(and)(or)<>=]+)\s*([<>=])\s*([^\s(and)(or)<>=]+)/u ) { - "#$1 #$2 #$3 and #$3 #$4 #$5" - } + predicate.gsub!( /([^\s(and)(or)<>=]+)\s*([<>=])\s*([^\s(and)(or)<>=]+)\s*([<>=])\s*([^\s(and)(or)<>=]+)/u, + '\1 \2 \3 and \3 \4 \5' ) # Let's do some Ruby trickery to avoid some work: predicate.gsub!( /&/u, "&&" ) predicate.gsub!( /=/u, "==" ) - predicate.gsub!( /@(\w[-\w.]*)/u ) { - "attribute(\"#$1\")" - } + predicate.gsub!( /@(\w[-\w.]*)/u, 'attribute("\1")' ) predicate.gsub!( /\bmod\b/u, "%" ) predicate.gsub!( /\b(\w[-\w.]*\()/u ) { fname = $1 diff --git a/vendor/plugins/rexml/lib/rexml/rexml.rb b/vendor/plugins/rexml/lib/rexml/rexml.rb index 6ace202a..891ef208 100644 --- a/vendor/plugins/rexml/lib/rexml/rexml.rb +++ b/vendor/plugins/rexml/lib/rexml/rexml.rb @@ -11,8 +11,8 @@ # # Main page:: http://www.germane-software.com/software/rexml # Author:: Sean Russell -# Version:: 3.1.7.2 -# Date:: 2007/275 +# Version:: 3.1.7.4 +# Date:: 2008/100 # # This API documentation can be downloaded from the REXML home page, or can # be accessed online[http://www.germane-software.com/software/rexml_doc] @@ -21,10 +21,10 @@ # or can be accessed # online[http://www.germane-software.com/software/rexml/docs/tutorial.html] module REXML - COPYRIGHT = "Copyright © 2001-2007 Sean Russell " - DATE = "2007/275" - VERSION = "3.1.7.2" - REVISION = "$Revision: 1284 $".gsub(/\$Revision:|\$/,'').strip + COPYRIGHT = "Copyright © 2001-2008 Sean Russell " + DATE = "2008/100" + VERSION = "3.1.7.4" + REVISION = "$Revision: 1312 $".gsub(/\$Revision:|\$/,'').strip Copyright = COPYRIGHT Version = VERSION diff --git a/vendor/plugins/rexml/lib/rexml/text.rb b/vendor/plugins/rexml/lib/rexml/text.rb index c23cd17c..8bc87dbf 100644 --- a/vendor/plugins/rexml/lib/rexml/text.rb +++ b/vendor/plugins/rexml/lib/rexml/text.rb @@ -50,7 +50,7 @@ module REXML | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 - )*$/x; + )*$/nx; end # Constructor @@ -139,7 +139,7 @@ module REXML end end else - string.scan(/[\x00-\x7F]|[\x80-\xBF][\xC0-\xF0]*|[\xC0-\xF0]/) do |c| + string.scan(/[\x00-\x7F]|[\x80-\xBF][\xC0-\xF0]*|[\xC0-\xF0]/n) do |c| case c.unpack('U') when *VALID_CHAR else @@ -345,7 +345,7 @@ module REXML copy.gsub!( SETUTITSBUS[2], SLAICEPS[2] ) copy.gsub!( SETUTITSBUS[3], SLAICEPS[3] ) copy.gsub!( SETUTITSBUS[4], SLAICEPS[4] ) - copy.gsub!( /�*((?:\d+)|(?:x[a-f0-9]+));/ ) {|m| + copy.gsub!( /�*((?:\d+)|(?:x[a-f0-9]+));/ ) { m=$1 #m='0' if m=='' m = "0#{m}" if m[0] == ?x @@ -380,7 +380,8 @@ module REXML # Unescapes all possible entities def Text::unnormalize( string, doctype=nil, filter=nil, illegal=nil ) - string.gsub( /\r\n?/, "\n" ).gsub( REFERENCE ) { |ref| + string.gsub( /\r\n?/, "\n" ).gsub( REFERENCE ) { + ref = $& if ref[1] == ?# if ref[2] == ?x [ref[3...-1].to_i(16)].pack('U*')