mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Merged from REXML main repository:
Fixes ticket:68. NOTE that this involves an API change! Entity declarations in the doctype now generate events that carry two, not one, arguments. Implements ticket:15, using gwrite's suggestion. This allows Element to be subclassed. Two unrelated changes, because subversion is retarded and doesn't do block-level commits: 1) Fixed a typo bug in previous change for ticket:15 2) Fixed namespaces handling in XPath and element. ***** Note that this is an API change!!! ***** Element.namespaces() now returns a hash of namespace mappings which are relevant for that node. Fixes a bug in multiple decodings The changeset 1230:1231 was bad. The default behavior is *not* to use the native REXML encodings by default, but rather to use ICONV by default. I know that this will piss some people off, but defaulting to the pure Ruby version isn't the correct solution, and it breaks other encodings, so I've reverted it. * Fixes ticket:61 (xpath_parser) * Fixes ticket:63 (UTF-16; UNILE decoding was bad) * Cleans up some tests, removing opportunities for test corruption * Improves parsing error messages a little * Adds the ability to override the encoding detection in Source construction * Fixes an edge case in Functions::string, where document nodes weren't correctly converted * Fixes Functions::string() for Element and Document nodes * Fixes some problems in entity handling Addresses ticket:66 Fixes ticket:71 Addresses ticket:78 NOTE: that this also fixes what is technically another bug in REXML. REXML's XPath parser used to allow exponential notation in numbers. The XPath spec is specific about what a number is, and scientific notation is not included. Therefore, this has been fixed. Cross-ported a fix for ticket:88 from CVS. Fixes ticket:80 Documentation cleanup. Ticket:84 Applied Kou's fix for an un-trac'ed bug. ------------------------------------------------------------------------ git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11548 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f700c1354f
commit
fa4bfa6af5
13 changed files with 142 additions and 83 deletions
|
@ -160,8 +160,13 @@ module REXML
|
|||
node_types = ELEMENTS
|
||||
return nodeset if path_stack.length == 0 || nodeset.length == 0
|
||||
while path_stack.length > 0
|
||||
#puts "#"*5
|
||||
#puts "Path stack = #{path_stack.inspect}"
|
||||
#puts "Nodeset is #{nodeset.inspect}"
|
||||
if nodeset.length == 0
|
||||
path_stack.clear
|
||||
return []
|
||||
end
|
||||
case (op = path_stack.shift)
|
||||
when :document
|
||||
nodeset = [ nodeset[0].root_node ]
|
||||
|
@ -235,9 +240,11 @@ module REXML
|
|||
name = path_stack.shift
|
||||
for element in nodeset
|
||||
if element.node_type == :element
|
||||
#puts element.name
|
||||
attr = element.attribute( name, get_namespace(element, prefix) )
|
||||
new_nodeset << attr if attr
|
||||
#puts "Element name = #{element.name}"
|
||||
#puts "get_namespace( #{element.inspect}, #{prefix} ) = #{get_namespace(element, prefix)}"
|
||||
attrib = element.attribute( name, get_namespace(element, prefix) )
|
||||
#puts "attrib = #{attrib.inspect}"
|
||||
new_nodeset << attrib if attrib
|
||||
end
|
||||
end
|
||||
when :any
|
||||
|
@ -299,8 +306,10 @@ module REXML
|
|||
#puts "Adding node #{node.inspect}" if result == (index+1)
|
||||
new_nodeset << node if result == (index+1)
|
||||
elsif result.instance_of? Array
|
||||
#puts "Adding node #{node.inspect}" if result.size > 0
|
||||
new_nodeset << node if result.size > 0
|
||||
if result.size > 0 and result.inject(false) {|k,s| s or k}
|
||||
#puts "Adding node #{node.inspect}" if result.size > 0
|
||||
new_nodeset << node if result.size > 0
|
||||
end
|
||||
else
|
||||
#puts "Adding node #{node.inspect}" if result
|
||||
new_nodeset << node if result
|
||||
|
@ -381,9 +390,25 @@ module REXML
|
|||
node_types = ELEMENTS
|
||||
|
||||
when :namespace
|
||||
new_set = []
|
||||
#puts "In :namespace"
|
||||
new_nodeset = []
|
||||
prefix = path_stack.shift
|
||||
for node in nodeset
|
||||
new_nodeset << node.namespace if node.node_type == :element or node.node_type == :attribute
|
||||
if (node.node_type == :element or node.node_type == :attribute)
|
||||
if @namespaces
|
||||
namespaces = @namespaces
|
||||
elsif (node.node_type == :element)
|
||||
namespaces = node.namespaces
|
||||
else
|
||||
namespaces = node.element.namesapces
|
||||
end
|
||||
#puts "Namespaces = #{namespaces.inspect}"
|
||||
#puts "Prefix = #{prefix.inspect}"
|
||||
#puts "Node.namespace = #{node.namespace}"
|
||||
if (node.namespace == namespaces[prefix])
|
||||
new_nodeset << node
|
||||
end
|
||||
end
|
||||
end
|
||||
nodeset = new_nodeset
|
||||
|
||||
|
@ -404,6 +429,18 @@ module REXML
|
|||
#puts "RES => #{res.inspect}"
|
||||
return res
|
||||
|
||||
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 []
|
||||
end
|
||||
right = expr( path_stack.shift, nodeset.dup, context )
|
||||
#puts "RIGHT => #{right.inspect} (#{right.class.name})"
|
||||
res = equality_relational_compare( left, op, right )
|
||||
#puts "RES => #{res.inspect}"
|
||||
return res
|
||||
|
||||
when :div
|
||||
left = Functions::number(expr(path_stack.shift, nodeset, context)).to_f
|
||||
right = Functions::number(expr(path_stack.shift, nodeset, context)).to_f
|
||||
|
@ -477,7 +514,7 @@ module REXML
|
|||
# The next two methods are BAD MOJO!
|
||||
# This is my achilles heel. If anybody thinks of a better
|
||||
# way of doing this, be my guest. This really sucks, but
|
||||
# it took me three days to get it to work at all.
|
||||
# it is a wonder it works at all.
|
||||
# ########################################################
|
||||
|
||||
def descendant_or_self( path_stack, nodeset )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue