Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update REXML (from ruby MRI)

  • Loading branch information...
commit 834e54f226c06d8adb684dbfc24733d6caf7dd59 1 parent f0b98aa
@LTe LTe authored
Showing with 190 additions and 189 deletions.
  1. +1 −1  lib/18/rexml/element.rb
  2. +2 −2 lib/18/rexml/encodings/SHIFT-JIS.rb
  3. +2 −2 lib/18/rexml/rexml.rb
  4. +1 −1  lib/18/rexml/text.rb
  5. +1 −1  lib/19/rexml/attribute.rb
  6. +1 −1  lib/19/rexml/cdata.rb
  7. +2 −2 lib/19/rexml/child.rb
  8. +6 −6 lib/19/rexml/comment.rb
  9. +5 −6 lib/19/rexml/doctype.rb
  10. +4 −3 lib/19/rexml/document.rb
  11. +18 −19 lib/19/rexml/element.rb
  12. +49 −58 lib/19/rexml/encoding.rb
  13. +1 −1  lib/19/rexml/formatters/default.rb
  14. +8 −6 lib/19/rexml/formatters/pretty.rb
  15. +0 −1  lib/19/rexml/formatters/transitive.rb
  16. +7 −1 lib/19/rexml/functions.rb
  17. +6 −7 lib/19/rexml/light/node.rb
  18. +6 −6 lib/19/rexml/node.rb
  19. +1 −1  lib/19/rexml/output.rb
  20. +1 −1  lib/19/rexml/parseexception.rb
  21. +12 −17 lib/19/rexml/parsers/baseparser.rb
  22. +4 −4 lib/19/rexml/parsers/lightparser.rb
  23. +5 −5 lib/19/rexml/parsers/sax2parser.rb
  24. +4 −4 lib/19/rexml/parsers/ultralightparser.rb
  25. +2 −3 lib/19/rexml/parsers/xpathparser.rb
  26. +15 −16 lib/19/rexml/quickpath.rb
  27. +1 −1  lib/19/rexml/rexml.rb
  28. +2 −4 lib/19/rexml/source.rb
  29. +1 −1  lib/19/rexml/text.rb
  30. +1 −1  lib/19/rexml/validation/validation.rb
  31. +8 −5 lib/19/rexml/xpath.rb
  32. +13 −2 lib/19/rexml/xpath_parser.rb
View
2  lib/18/rexml/element.rb
@@ -492,7 +492,7 @@ def get_text path = nil
def text=( text )
if text.kind_of? String
text = Text.new( text, whitespace(), nil, raw() )
- elsif text and !text.kind_of? Text
+ elsif !text.nil? and !text.kind_of? Text
text = Text.new( text.to_s, whitespace(), nil, raw() )
end
old_text = get_text
View
4 lib/18/rexml/encodings/SHIFT-JIS.rb
@@ -13,8 +13,8 @@ def encode_sjis(str)
rescue LoadError
require 'nkf'
- SJISTOU8 = '-Swm0'
- U8TOSJIS = '-Wsm0'
+ SJISTOU8 = '-Swm0x'
+ U8TOSJIS = '-Wsm0x'
def decode_sjis(str)
NKF.nkf(SJISTOU8, str)
View
4 lib/18/rexml/rexml.rb
@@ -13,7 +13,7 @@
# Author:: Sean Russell <serATgermaneHYPHENsoftwareDOTcom>
# Version:: 3.1.7.2
# Date:: 2007/275
-# Revision:: $Revision: 22842 $
+# Revision:: $Revision$
#
# This API documentation can be downloaded from the REXML home page, or can
# be accessed online[http://www.germane-software.com/software/rexml_doc]
@@ -25,7 +25,7 @@ module REXML
COPYRIGHT = "Copyright \xC2\xA9 2001-2006 Sean Russell <ser@germane-software.com>"
VERSION = "3.1.7.3"
DATE = "2007/275"
- REVISION = "$Revision: 22842 $".gsub(/\$Revision:|\$/,'').strip
+ REVISION = "$Revision$".gsub(/\$Revision:|\$/,'').strip
Copyright = COPYRIGHT
Version = VERSION
View
2  lib/18/rexml/text.rb
@@ -286,7 +286,7 @@ def Text::read_with_substitution( input, illegal=nil )
EREFERENCE = /&(?!#{Entity::NAME};)/
# Escapes all possible entities
def Text::normalize( input, doctype=nil, entity_filter=nil )
- copy = input
+ copy = input.to_s
# Doing it like this rather than in a loop improves the speed
#copy = copy.gsub( EREFERENCE, '&amp;' )
copy = copy.gsub( "&", "&amp;" )
View
2  lib/19/rexml/attribute.rb
@@ -115,7 +115,7 @@ def to_string
def doctype
if @element
doc = @element.document
- doctype = doc.doctype if doc
+ doc.doctype if doc
end
end
View
2  lib/19/rexml/cdata.rb
@@ -6,7 +6,7 @@ class CData < Text
STOP = ']]>'
ILLEGAL = /(\]\]>)/
- # Constructor. CData is data between <![CDATA[ ... ]]>
+ # Constructor. CData is data between <![CDATA[ ... ]]>
#
# _Examples_
# CData.new( source )
View
4 lib/19/rexml/child.rb
@@ -7,7 +7,7 @@ module REXML
# class directly.
class Child
include Node
- attr_reader :parent # The Parent of this object
+ attr_reader :parent # The Parent of this object
# Constructor. Any inheritors of this class should call super to make
# sure this method is called.
@@ -88,7 +88,7 @@ def document
# This doesn't yet handle encodings
def bytes
- encoding = document.encoding
+ document.encoding
to_s
end
View
12 lib/19/rexml/comment.rb
@@ -38,15 +38,15 @@ def clone
# See REXML::Formatters
#
# output::
- # Where to write the string
+ # Where to write the string
# indent::
- # An integer. If -1, no indenting will be used; otherwise, the
- # indentation will be this number of spaces, and children will be
- # indented an additional amount.
+ # An integer. If -1, no indenting will be used; otherwise, the
+ # indentation will be this number of spaces, and children will be
+ # indented an additional amount.
# transitive::
- # Ignored by this class. The contents of comments are never modified.
+ # Ignored by this class. The contents of comments are never modified.
# ie_hack::
- # Needed for conformity to the child API, but not used by this class.
+ # Needed for conformity to the child API, but not used by this class.
def write( output, indent=-1, transitive=false, ie_hack=false )
Kernel.warn("Comment.write is deprecated. See REXML::Formatters")
indent( output, indent )
View
11 lib/19/rexml/doctype.rb
@@ -115,7 +115,6 @@ def write( output, indent=0, transitive=false, ie_hack=false )
output << " #{@long_name.inspect}" if @long_name
output << " #{@uri.inspect}" if @uri
unless @children.empty?
- next_indent = indent + 1
output << ' ['
@children.each { |child|
output << "\n"
@@ -249,11 +248,11 @@ def initialize name, middle, pub, sys
end
def to_s
- "<!NOTATION #@name #@middle#{
- @public ? ' ' + public.inspect : ''
- }#{
- @system ? ' ' +@system.inspect : ''
- }>"
+ notation = "<!NOTATION #{@name} #{@middle}"
+ notation << " #{@public.inspect}" if @public
+ notation << " #{@system.inspect}" if @system
+ notation << ">"
+ notation
end
def write( output, indent=-1 )
View
7 lib/19/rexml/document.rb
@@ -131,7 +131,8 @@ def version
xml_decl().version
end
- # @return the XMLDecl encoding of this document as a String.
+ # @return the XMLDecl encoding of this document as an
+ # Encoding object.
# If no XMLDecl has been set, returns the default encoding.
def encoding
xml_decl().encoding
@@ -164,7 +165,7 @@ def stand_alone?
# Document.new("<a><b/></a>").serialize( tr )
#
# output::
- # output an object which supports '<< string'; this is where the
+ # output an object which supports '<< string'; this is where the
# document will be written.
# indent::
# An integer. If -1, no indenting will be used; otherwise, the
@@ -183,7 +184,7 @@ def stand_alone?
# that IE's limited abilities can handle. This hack inserts a space
# before the /> on empty tags. Defaults to false
def write( output=$stdout, indent=-1, transitive=false, ie_hack=false )
- if xml_decl.encoding != "UTF-8" && !output.kind_of?(Output)
+ if xml_decl.encoding != 'UTF-8' && !output.kind_of?(Output)
output = Output.new( output, xml_decl.encoding )
end
formatter = if indent > -1
View
37 lib/19/rexml/element.rb
@@ -20,7 +20,7 @@ module REXML
class Element < Parent
include Namespace
- UNDEFINED = "UNDEFINED"; # The default name
+ UNDEFINED = "UNDEFINED"; # The default name
# Mechanisms for accessing attributes and child elements of this
# element.
@@ -31,17 +31,17 @@ class Element < Parent
# Constructor
# arg::
- # if not supplied, will be set to the default value.
- # If a String, the name of this object will be set to the argument.
- # If an Element, the object will be shallowly cloned; name,
- # attributes, and namespaces will be copied. Children will +not+ be
- # copied.
+ # if not supplied, will be set to the default value.
+ # If a String, the name of this object will be set to the argument.
+ # If an Element, the object will be shallowly cloned; name,
+ # attributes, and namespaces will be copied. Children will +not+ be
+ # copied.
# parent::
- # if supplied, must be a Parent, and will be used as
- # the parent of this object.
+ # if supplied, must be a Parent, and will be used as
+ # the parent of this object.
# context::
- # If supplied, must be a hash containing context items. Context items
- # include:
+ # If supplied, must be a hash containing context items. Context items
+ # include:
# * <tt>:respect_whitespace</tt> the value of this is :+all+ or an array of
# strings being the names of the elements to respect
# whitespace for. Defaults to :+all+.
@@ -297,7 +297,7 @@ def add_element element, attrs=nil
el = @elements.add(element)
attrs.each do |key, value|
el.attributes[key]=value
- end if attrs.kind_of? Hash
+ end if attrs.kind_of? Hash
el
end
@@ -667,7 +667,7 @@ def texts
#
# Writes out this element, and recursively, all children.
# output::
- # output an object which supports '<< string'; this is where the
+ # output an object which supports '<< string'; this is where the
# document will be written.
# indent::
# An integer. If -1, no indenting will be used; otherwise, the
@@ -778,7 +778,7 @@ def []( index, name=nil)
else
return XPath::first( @element, index )
#{ |element|
- # return element if element.kind_of? Element
+ # return element if element.kind_of? Element
#}
#return nil
end
@@ -874,7 +874,6 @@ def delete_all( xpath )
# a.elements.add(Element.new('b')) #-> <a><b/></a>
# a.elements.add('c') #-> <a><b/><c/></a>
def add element=nil
- rv = nil
if element.nil?
Element.new("", self, @element.context)
elsif not element.kind_of?(Element)
@@ -1087,12 +1086,12 @@ def get_attribute( name )
# doc.root.attributes['foo'] = '4'
# doc.root.attributes['x:foo'] = nil
def []=( name, value )
- if value.nil? # Delete the named attribute
+ if value.nil? # Delete the named attribute
attr = get_attribute(name)
delete attr
return
end
- element_document = @element.document
+
unless value.kind_of? Attribute
if @element.document and @element.document.doctype
value = Text::normalize( value, @element.document.doctype )
@@ -1117,8 +1116,8 @@ def []=( name, value )
value.prefix != "xmlns" and old_attr.prefix != "xmlns" and
@element.namespace( old_attr.prefix ) ==
@element.namespace( value.prefix )
- store value.name, { old_attr.prefix => old_attr,
- value.prefix => value }
+ store value.name, { old_attr.prefix => old_attr,
+ value.prefix => value }
else
store value.name, value
end
@@ -1197,7 +1196,7 @@ def delete( attribute )
return @element
else # the supplied attribute is a top-level one
attr = old
- res = super(name)
+ super(name)
end
@element
end
View
107 lib/19/rexml/encoding.rb
@@ -1,71 +1,62 @@
-# -*- mode: ruby; ruby-indent-level: 2; indent-tabs-mode: t; tab-width: 2 -*- vim: sw=2 ts=2
module REXML
module Encoding
- @encoding_methods = {}
- def self.register(enc, &block)
- @encoding_methods[enc] = block
- end
- def self.apply(obj, enc)
- @encoding_methods[enc][obj]
- end
- def self.encoding_method(enc)
- @encoding_methods[enc]
- end
-
- # Native, default format is UTF-8, so it is declared here rather than in
- # an encodings/ definition.
- UTF_8 = 'UTF-8'
- UTF_16 = 'UTF-16'
- UNILE = 'UNILE'
-
# ID ---> Encoding name
attr_reader :encoding
- def encoding=( enc )
- old_verbosity = $VERBOSE
- begin
- $VERBOSE = false
- enc = enc.nil? ? nil : enc.upcase
- return false if defined? @encoding and enc == @encoding
- if enc and enc != UTF_8
- @encoding = enc
- raise ArgumentError, "Bad encoding name #@encoding" unless @encoding =~ /^[\w-]+$/
- @encoding.untaint
- begin
- require 'rexml/encodings/ICONV.rb'
- Encoding.apply(self, "ICONV")
- rescue LoadError, Exception
- begin
- enc_file = File.join( "rexml", "encodings", "#@encoding.rb" )
- require enc_file
- Encoding.apply(self, @encoding)
- rescue LoadError => err
- puts err.message
- raise ArgumentError, "No decoder found for encoding #@encoding. Please install iconv."
- end
- end
- else
- @encoding = UTF_8
- require 'rexml/encodings/UTF-8.rb'
- Encoding.apply(self, @encoding)
+ def encoding=(encoding)
+ encoding = encoding.name if encoding.is_a?(Encoding)
+ if encoding.is_a?(String)
+ original_encoding = encoding
+ encoding = find_encoding(encoding)
+ unless encoding
+ raise ArgumentError, "Bad encoding name #{original_encoding}"
end
- ensure
- $VERBOSE = old_verbosity
+ end
+ return false if defined?(@encoding) and encoding == @encoding
+ if encoding
+ @encoding = encoding.upcase
+ else
+ @encoding = 'UTF-8'
end
true
end
- def check_encoding str
- # We have to recognize UTF-16, LSB UTF-16, and UTF-8
- if str[0,2] == "\xfe\xff"
- str[0,2] = ""
- return UTF_16
- elsif str[0,2] == "\xff\xfe"
- str[0,2] = ""
- return UNILE
+ def check_encoding(xml)
+ # We have to recognize UTF-16BE, UTF-16LE, and UTF-8
+ if xml[0, 2] == "\xfe\xff"
+ xml[0, 2] = ""
+ return 'UTF-16BE'
+ elsif xml[0, 2] == "\xff\xfe"
+ xml[0, 2] = ""
+ return 'UTF-16LE'
+ end
+ xml =~ /^\s*<\?xml\s+version\s*=\s*(['"]).*?\1\s+encoding\s*=\s*(["'])(.*?)\2/m
+ return $3 ? $3.upcase : 'UTF-8'
+ end
+
+ def encode(string)
+ string.encode(@encoding)
+ end
+
+ def decode(string)
+ string.encode(::Encoding::UTF_8, @encoding)
+ end
+
+ private
+ def find_encoding(name)
+ case name
+ when /\Ashift-jis\z/i
+ return "SHIFT_JIS"
+ when /\ACP-(\d+)\z/
+ name = "CP#{$1}"
+ when /\AUTF-8\z/i
+ return name
+ end
+ begin
+ ::Encoding::Converter.search_convpath(name, 'UTF-8')
+ rescue ::Encoding::ConverterNotFoundError
+ return nil
end
- str =~ /^\s*<\?xml\s+version\s*=\s*(['"]).*?\1\s+encoding\s*=\s*(["'])(.*?)\2/m
- return $3.upcase if $3
- return UTF_8
+ name
end
end
end
View
2  lib/19/rexml/formatters/default.rb
@@ -22,7 +22,7 @@ def write( node, output )
case node
when Document
- if node.xml_decl.encoding != "UTF-8" && !output.kind_of?(Output)
+ if node.xml_decl.encoding != 'UTF-8' && !output.kind_of?(Output)
output = Output.new( output, node.xml_decl.encoding )
end
write_document( node, output )
View
14 lib/19/rexml/formatters/pretty.rb
@@ -88,7 +88,7 @@ def write_text( node, output )
s = node.to_s()
s.gsub!(/\s/,' ')
s.squeeze!(" ")
- s = wrap(s, 80-@level)
+ s = wrap(s, @width - @level)
s = indent_text(s, @level, " ", true)
output << (' '*@level + s)
end
@@ -126,11 +126,13 @@ def indent_text(string, level=1, style="\t", indentfirstline=true)
end
def wrap(string, width)
- # Recursively wrap string at width.
- return string if string.length <= width
- place = string.rindex(' ', width) # Position in string with last ' ' before cutoff
- return string if place.nil?
- return string[0,place] + "\n" + wrap(string[place+1..-1], width)
+ parts = []
+ while string.length > width and place = string.rindex(' ', width)
+ parts << string[0...place]
+ string = string[place+1..-1]
+ end
+ parts << string
+ parts.join("\n")
end
end
View
1  lib/19/rexml/formatters/transitive.rb
@@ -37,7 +37,6 @@ def write_element( node, output )
# If compact and all children are text, and if the formatted output
# is less than the specified width, then try to print everything on
# one line
- skip = false
@level += @indentation
node.children.each { |child|
write( child, output )
View
8 lib/19/rexml/functions.rb
@@ -28,6 +28,7 @@ def Functions::text( )
end
end
+ # Returns the last node of the given list of nodes.
def Functions::last( )
@@context[:size]
end
@@ -36,6 +37,7 @@ def Functions::position( )
@@context[:index]
end
+ # Returns the size of the given list of nodes.
def Functions::count( node_set )
node_set.size
end
@@ -129,6 +131,11 @@ def Functions::string( object=nil )
end
end
+ # A node-set is converted to a string by
+ # returning the concatenation of the string-value
+ # of each of the children of the node in the
+ # node-set that is first in document order.
+ # If the node-set is empty, an empty string is returned.
def Functions::string_value( o )
rv = ""
o.children.each { |e|
@@ -170,7 +177,6 @@ def Functions::substring_before( string, test )
# Kouhei fixed this too
def Functions::substring_after( string, test )
ruby_string = string(string)
- test_string = string(test)
return $1 if ruby_string =~ /#{test}(.*)/
""
end
View
13 lib/19/rexml/light/node.rb
@@ -1,14 +1,13 @@
require 'rexml/xmltokens'
-require 'rexml/light/node'
# [ :element, parent, name, attributes, children* ]
# a = Node.new
- # a << "B" # => <a>B</a>
- # a.b # => <a>B<b/></a>
- # a.b[1] # => <a>B<b/><b/><a>
- # a.b[1]["x"] = "y" # => <a>B<b/><b x="y"/></a>
- # a.b[0].c # => <a>B<b><c/></b><b x="y"/></a>
- # a.b.c << "D" # => <a>B<b><c>D</c></b><b x="y"/></a>
+ # a << "B" # => <a>B</a>
+ # a.b # => <a>B<b/></a>
+ # a.b[1] # => <a>B<b/><b/><a>
+ # a.b[1]["x"] = "y" # => <a>B<b/><b x="y"/></a>
+ # a.b[0].c # => <a>B<b><c/></b><b x="y"/></a>
+ # a.b.c << "D" # => <a>B<b><c>D</c></b><b x="y"/></a>
module REXML
module Light
# Represents a tagged XML element. Elements are characterized by
View
12 lib/19/rexml/node.rb
@@ -36,12 +36,12 @@ def to_s indent=nil
end
def indent to, ind
- if @parent and @parent.context and not @parent.context[:indentstyle].nil? then
- indentstyle = @parent.context[:indentstyle]
- else
- indentstyle = ' '
- end
- to << indentstyle*ind unless ind<1
+ if @parent and @parent.context and not @parent.context[:indentstyle].nil? then
+ indentstyle = @parent.context[:indentstyle]
+ else
+ indentstyle = ' '
+ end
+ to << indentstyle*ind unless ind<1
end
def parent?
View
2  lib/19/rexml/output.rb
@@ -10,7 +10,7 @@ def initialize real_IO, encd="iso-8859-1"
@output = real_IO
self.encoding = encd
- @to_utf = encd == UTF_8 ? false : true
+ @to_utf = encd != 'UTF-8'
end
def <<( content )
View
2  lib/19/rexml/parseexception.rb
@@ -28,7 +28,7 @@ def to_s
err << "\nLine: #{line}\n"
err << "Position: #{position}\n"
err << "Last 80 unconsumed characters:\n"
- err << @source.buffer[0..80].gsub(/\n/, ' ')
+ err << @source.buffer[0..80].force_encoding("ASCII-8BIT").gsub(/\n/, ' ')
end
err
View
29 lib/19/rexml/parsers/baseparser.rb
@@ -114,22 +114,10 @@ class BaseParser
def initialize( source )
self.stream = source
+ @listeners = []
end
def add_listener( listener )
- if !defined?(@listeners) or !@listeners
- @listeners = []
- instance_eval <<-EOL
- alias :_old_pull :pull
- def pull
- event = _old_pull
- @listeners.each do |listener|
- listener.receive event
- end
- event
- end
- EOL
- end
@listeners << listener
end
@@ -192,6 +180,14 @@ def peek depth=0
# Returns the next event. This is a +PullEvent+ object.
def pull
+ pull_event.tap do |event|
+ @listeners.each do |listener|
+ listener.receive event
+ end
+ end
+ end
+
+ def pull_event
if @closed
x, @closed = @closed, nil
return [ :end_element, x ]
@@ -249,9 +245,7 @@ def pull
@source.read if @source.buffer.size<2
md = @source.match(/\s*/um, true)
if @source.encoding == "UTF-8"
- if @source.buffer.respond_to? :force_encoding
- @source.buffer.force_encoding(Encoding::UTF_8)
- end
+ @source.buffer.force_encoding(::Encoding::UTF_8)
end
end
end
@@ -382,7 +376,7 @@ def pull
attrs.each { |a,b,c,d,e|
if b == "xmlns"
if c == "xml"
- if d != "http://www.w3.org/XML/1998/namespace"
+ if e != "http://www.w3.org/XML/1998/namespace"
msg = "The 'xml' prefix must not be bound to any other namespace "+
"(http://www.w3.org/TR/REC-xml-names/#ns-decl)"
raise REXML::ParseException.new( msg, @source, self )
@@ -442,6 +436,7 @@ def pull
end
return [ :dummy ]
end
+ private :pull_event
def entity( reference, entities )
value = nil
View
8 lib/19/rexml/parsers/lightparser.rb
@@ -44,10 +44,10 @@ def parse
end
# An element is an array. The array contains:
- # 0 The parent element
- # 1 The tag name
- # 2 A hash of attributes
- # 3..-1 The child elements
+ # 0 The parent element
+ # 1 The tag name
+ # 2 A hash of attributes
+ # 3..-1 The child elements
# An element is an array of size > 3
# Text is a String
# PIs are [ :processing_instruction, target, data ]
View
10 lib/19/rexml/parsers/sax2parser.rb
@@ -28,15 +28,15 @@ def add_listener( listener )
# Listen arguments:
#
# Symbol, Array, Block
- # Listen to Symbol events on Array elements
+ # Listen to Symbol events on Array elements
# Symbol, Block
# Listen to Symbol events
# Array, Listener
- # Listen to all events on Array elements
+ # Listen to all events on Array elements
# Array, Block
- # Listen to :start_element events on Array elements
+ # Listen to :start_element events on Array elements
# Listener
- # Listen to All events
+ # Listen to All events
#
# Symbol can be one of: :start_element, :end_element,
# :start_prefix_mapping, :end_prefix_mapping, :characters,
@@ -87,7 +87,7 @@ def parse
@listeners.each { |sym,match,block|
block.start_document if sym == :start_document or sym.nil?
}
- root = context = []
+ context = []
while true
event = @parser.pull
case event[0]
View
8 lib/19/rexml/parsers/ultralightparser.rb
@@ -42,10 +42,10 @@ def parse
end
# An element is an array. The array contains:
- # 0 The parent element
- # 1 The tag name
- # 2 A hash of attributes
- # 3..-1 The child elements
+ # 0 The parent element
+ # 1 The tag name
+ # 2 A hash of attributes
+ # 3..-1 The child elements
# An element is an array of size > 3
# Text is a String
# PIs are [ :processing_instruction, target, data ]
View
5 lib/19/rexml/parsers/xpathparser.rb
@@ -17,8 +17,9 @@ def namespaces=( namespaces )
end
def parse path
+ path = path.dup
path.gsub!(/([\(\[])\s+/, '\1') # Strip ignorable spaces
- path.gsub!( /\s+([\]\)])/, '\1' )
+ path.gsub!( /\s+([\]\)])/, '\1')
parsed = []
path = OrExpr(path, parsed)
parsed
@@ -282,7 +283,6 @@ def RelativeLocationPath path, parsed
PI = /^processing-instruction\(/
def NodeTest path, parsed
#puts "NodeTest with #{path}"
- res = nil
case path
when /^\*/
path = $'
@@ -578,7 +578,6 @@ def FilterExpr path, parsed
NUMBER = /^(\d*\.?\d+)/
NT = /^comment|text|processing-instruction|node$/
def PrimaryExpr path, parsed
- arry = []
case path
when VARIABLE_REFERENCE
varname = $1
View
31 lib/19/rexml/quickpath.rb
@@ -6,6 +6,8 @@ class QuickPath
include Functions
include XMLTokens
+ # A base Hash object to be used when initializing a
+ # default empty namespaces set.
EMPTY_HASH = {}
def QuickPath::first element, path, namespaces=EMPTY_HASH
@@ -33,7 +35,6 @@ def QuickPath::match element, path, namespaces=EMPTY_HASH
results = filter(element.to_a, path)
when /^[\[!\w:]/u
# match on child
- matches = []
children = element.to_a
results = filter(children, path)
else
@@ -48,22 +49,20 @@ def QuickPath::match element, path, namespaces=EMPTY_HASH
def QuickPath::filter elements, path
return elements if path.nil? or path == '' or elements.size == 0
case path
- when /^\/\//u # Descendant
+ when /^\/\//u # Descendant
return axe( elements, "descendant-or-self", $' )
- when /^\/?\b(\w[-\w]*)\b::/u # Axe
- axe_name = $1
- rest = $'
+ when /^\/?\b(\w[-\w]*)\b::/u # Axe
return axe( elements, $1, $' )
- when /^\/(?=\b([:!\w][-\.\w]*:)?[-!\*\.\w]*\b([^:(]|$)|\*)/u # Child
+ when /^\/(?=\b([:!\w][-\.\w]*:)?[-!\*\.\w]*\b([^:(]|$)|\*)/u # Child
rest = $'
results = []
elements.each do |element|
results |= filter( element.to_a, rest )
end
return results
- when /^\/?(\w[-\w]*)\(/u # / Function
+ when /^\/?(\w[-\w]*)\(/u # / Function
return function( elements, $1, $' )
- when Namespace::NAMESPLIT # Element name
+ when Namespace::NAMESPLIT # Element name
name = $2
ns = $1
rest = $'
@@ -80,22 +79,22 @@ def QuickPath::filter elements, path
matches |= predicate( element.to_a, path[1..-1] ) if element.kind_of? Element
end
return matches
- when /^\[/u # Predicate
+ when /^\[/u # Predicate
return predicate( elements, path )
- when /^\/?\.\.\./u # Ancestor
+ when /^\/?\.\.\./u # Ancestor
return axe( elements, "ancestor", $' )
- when /^\/?\.\./u # Parent
+ when /^\/?\.\./u # Parent
return filter( elements.collect{|e|e.parent}, $' )
- when /^\/?\./u # Self
+ when /^\/?\./u # Self
return filter( elements, $' )
- when /^\*/u # Any
+ when /^\*/u # Any
results = []
elements.each do |element|
results |= filter( [element], $' ) if element.kind_of? Element
#if element.kind_of? Element
- # children = element.to_a
- # children.delete_if { |child| !child.kind_of?(Element) }
- # results |= filter( children, $' )
+ # children = element.to_a
+ # children.delete_if { |child| !child.kind_of?(Element) }
+ # results |= filter( children, $' )
#end
end
return results
View
2  lib/19/rexml/rexml.rb
@@ -24,7 +24,7 @@ module REXML
COPYRIGHT = "Copyright © 2001-2008 Sean Russell <ser@germane-software.com>"
DATE = "2008/019"
VERSION = "3.1.7.3"
- REVISION = %w$Revision: 26193 $[1] || ''
+ REVISION = %w$Revision$[1] || ''
Copyright = COPYRIGHT
Version = VERSION
View
6 lib/19/rexml/source.rb
@@ -54,14 +54,12 @@ def initialize(arg, encoding=nil)
def encoding=(enc)
return unless super
@line_break = encode( '>' )
- if enc != UTF_8
+ if @encoding != 'UTF-8'
@buffer = decode(@buffer)
@to_utf = true
else
@to_utf = false
- if @buffer.respond_to? :force_encoding
- @buffer.force_encoding Encoding::UTF_8
- end
+ @buffer.force_encoding ::Encoding::UTF_8
end
end
View
2  lib/19/rexml/text.rb
@@ -105,7 +105,7 @@ def initialize(arg, respect_whitespace=false, parent=nil, raw=nil,
@normalized = @unnormalized = nil
if arg.kind_of? String
- @string = arg.clone
+ @string = arg.dup
@string.squeeze!(" \n\t") unless respect_whitespace
elsif arg.kind_of? Text
@string = arg.to_s
View
2  lib/19/rexml/validation/validation.rb
@@ -33,7 +33,7 @@ def validate( event )
sattr = [:start_attribute, nil]
eattr = [:end_attribute]
text = [:text, nil]
- k,v = event[2].find { |key,value|
+ k, = event[2].find { |key,value|
sattr[1] = key
#puts "Looking for #{sattr.inspect}"
m = @current.next( sattr )
View
13 lib/19/rexml/xpath.rb
@@ -5,16 +5,19 @@ module REXML
# Wrapper class. Use this class to access the XPath functions.
class XPath
include Functions
+ # A base Hash object, supposing to be used when initializing a
+ # default empty namespaces set, but is currently unused.
+ # TODO: either set the namespaces=EMPTY_HASH, or deprecate this.
EMPTY_HASH = {}
# Finds and returns the first node that matches the supplied xpath.
# element::
- # The context element
+ # The context element
# path::
- # The xpath to search for. If not supplied or nil, returns the first
- # node matching '*'.
+ # The xpath to search for. If not supplied or nil, returns the first
+ # node matching '*'.
# namespaces::
- # If supplied, a Hash which defines a namespace mapping.
+ # If supplied, a Hash which defines a namespace mapping.
# variables::
# If supplied, a Hash which maps $variables in the query
# to values. This can be used to avoid XPath injection attacks
@@ -42,7 +45,7 @@ def XPath::first element, path=nil, namespaces=nil, variables={}
# path::
# The xpath to search for. If not supplied or nil, defaults to '*'
# namespaces::
- # If supplied, a Hash which defines a namespace mapping
+ # If supplied, a Hash which defines a namespace mapping
# variables::
# If supplied, a Hash which maps $variables in the query
# to values. This can be used to avoid XPath injection attacks
View
15 lib/19/rexml/xpath_parser.rb
@@ -5,20 +5,30 @@
require 'rexml/parsers/xpathparser'
class Object
+ # provides a unified +clone+ operation, for REXML::XPathParser
+ # to use across multiple Object types
def dclone
clone
end
end
class Symbol
+ # provides a unified +clone+ operation, for REXML::XPathParser
+ # to use across multiple Object types
def dclone ; self ; end
end
class Fixnum
+ # provides a unified +clone+ operation, for REXML::XPathParser
+ # to use across multiple Object types
def dclone ; self ; end
end
class Float
+ # provides a unified +clone+ operation, for REXML::XPathParser
+ # to use across multiple Object types
def dclone ; self ; end
end
class Array
+ # provides a unified +clone+ operation, for REXML::XPathParser
+ # to use across multiple Object+ types
def dclone
klone = self.clone
klone.clear
@@ -434,7 +444,8 @@ def expr( path_stack, nodeset, context=nil )
when :and
left = expr( path_stack.shift, nodeset.dup, context )
#puts "LEFT => #{left.inspect} (#{left.class.name})"
- if left == false || left.nil? || !left.inject(false) {|a,b| a | b}
+ return [] unless left
+ if left.respond_to?(:inject) and !left.inject(false) {|a,b| a | b}
return []
end
right = expr( path_stack.shift, nodeset.dup, context )
@@ -686,7 +697,7 @@ def equality_relational_compare( set1, op, set2 )
return rv
else
res = []
- enum = SyncEnumerator.new( set1, set2 ).each { |i1, i2|
+ SyncEnumerator.new( set1, set2 ).each { |i1, i2|
#puts "i1 = #{i1.inspect} (#{i1.class.name})"
#puts "i2 = #{i2.inspect} (#{i2.class.name})"
i1 = norm( i1 )
Please sign in to comment.
Something went wrong with that request. Please try again.