mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
rexml: Fix a XPath bug of /child::node()
[Bug #14600] * lib/rexml/xpath_parser.rb: Fix a bug that "/child::node()" returns XML declaration and text nodes out of root element. * test/rexml/test_jaxen.rb: Enable more tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63088 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
478d3dffa2
commit
e440bfaed1
2 changed files with 30 additions and 11 deletions
|
@ -212,7 +212,19 @@ module REXML
|
|||
nodeset.each do |node|
|
||||
nt = node.node_type
|
||||
# trace(:child, nt, node)
|
||||
new_nodeset += node.children if nt == :element or nt == :document
|
||||
case nt
|
||||
when :element
|
||||
new_nodeset.concat(node.children)
|
||||
when :document
|
||||
node.children.each do |child|
|
||||
case child
|
||||
when XMLDecl, Text
|
||||
# ignore
|
||||
else
|
||||
new_nodeset << child
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
nodeset = new_nodeset
|
||||
node_types = ELEMENTS
|
||||
|
|
|
@ -21,8 +21,9 @@ module REXMLTests
|
|||
def test_id ; process_test_case("id") ; end
|
||||
def test_jaxen24 ; process_test_case("jaxen24") ; end
|
||||
def test_lang ; process_test_case("lang") ; end
|
||||
# document() function for XSLT isn't supported
|
||||
def _test_message ; process_test_case("message") ; end
|
||||
def _test_moreover ; process_test_case("moreover") ; end
|
||||
def test_moreover ; process_test_case("moreover") ; end
|
||||
def _test_much_ado ; process_test_case("much_ado") ; end
|
||||
def _test_namespaces ; process_test_case("namespaces") ; end
|
||||
def _test_nitf ; process_test_case("nitf") ; end
|
||||
|
@ -80,13 +81,7 @@ module REXMLTests
|
|||
xpath = value_of.attributes["select"]
|
||||
matched = XPath.first(context, xpath, namespaces, variables)
|
||||
|
||||
message = ""
|
||||
context.each_with_index do |node, i|
|
||||
message << "Node#{i}:\n"
|
||||
message << node.to_s
|
||||
end
|
||||
message << "XPath: <#{xpath}>\n"
|
||||
message << "Matched <#{matched.class}>"
|
||||
message = user_message(context, xpath, matched)
|
||||
|
||||
if expected.nil?
|
||||
assert_nil(matched, message)
|
||||
|
@ -117,11 +112,12 @@ module REXMLTests
|
|||
expected = test.attributes["count"]
|
||||
if expected
|
||||
assert_equal(Integer(expected, 10),
|
||||
matched.size)
|
||||
matched.size,
|
||||
user_message(context, xpath, matched))
|
||||
end
|
||||
|
||||
XPath.each(test, "valueOf") do |value_of|
|
||||
process_value_of(mathched, variables, namespaces, value_of)
|
||||
process_value_of(matched, variables, namespaces, value_of)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -132,5 +128,16 @@ module REXMLTests
|
|||
XPath.match(context, select, namespaces, variables)
|
||||
end
|
||||
end
|
||||
|
||||
def user_message(context, xpath, matched)
|
||||
message = ""
|
||||
context.each_with_index do |node, i|
|
||||
message << "Node#{i}:\n"
|
||||
message << "#{node}\n"
|
||||
end
|
||||
message << "XPath: <#{xpath}>\n"
|
||||
message << "Matched <#{matched}>"
|
||||
message
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue