diff options
author | kou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-04-04 06:53:57 +0000 |
---|---|---|
committer | kou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-04-04 06:53:57 +0000 |
commit | e440bfaed184b2fbbc37a838362a2f79280637cb (patch) | |
tree | 7d536cdc7acd7f6faac2b0e84fd75a1bc8acba2c | |
parent | 478d3dffa24a200dd595a7f50a58bb8ff3e1e0c0 (diff) |
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
-rw-r--r-- | lib/rexml/xpath_parser.rb | 14 | ||||
-rw-r--r-- | test/rexml/test_jaxen.rb | 27 |
2 files changed, 30 insertions, 11 deletions
diff --git a/lib/rexml/xpath_parser.rb b/lib/rexml/xpath_parser.rb index f663215b07..a94ad91ea1 100644 --- a/lib/rexml/xpath_parser.rb +++ b/lib/rexml/xpath_parser.rb @@ -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 diff --git a/test/rexml/test_jaxen.rb b/test/rexml/test_jaxen.rb index 069a24e359..703b2793d0 100644 --- a/test/rexml/test_jaxen.rb +++ b/test/rexml/test_jaxen.rb @@ -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 |