ruby-changes:50876
From: kou <ko1@a...>
Date: Wed, 4 Apr 2018 12:27:24 +0900 (JST)
Subject: [ruby-changes:50876] kou:r63083 (trunk): rexml: Fix a XPath bug of @attribute/parent
kou 2018-04-04 12:27:20 +0900 (Wed, 04 Apr 2018) New Revision: 63083 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63083 Log: rexml: Fix a XPath bug of @attribute/parent [Bug #14600] * lib/rexml/functions.rb: Fix a bug that "@attribute/parent" doesn't return element of its attribute. * test/rexml/test_jaxen.rb: Enable more tests. Modified files: trunk/lib/rexml/xpath_parser.rb trunk/test/rexml/test_jaxen.rb Index: lib/rexml/xpath_parser.rb =================================================================== --- lib/rexml/xpath_parser.rb (revision 63082) +++ lib/rexml/xpath_parser.rb (revision 63083) @@ -236,8 +236,16 @@ module REXML https://github.com/ruby/ruby/blob/trunk/lib/rexml/xpath_parser.rb#L236 nodeset = new_nodeset when :parent - nodeset = nodeset.collect{|n| n.parent}.compact - #nodeset = expr(path_stack.dclone, nodeset.collect{|n| n.parent}.compact) + new_nodeset = [] + nodeset.each do |node| + if node.is_a?(Attribute) + parent = node.element + else + parent = node.parent + end + new_nodeset << parent if parent + end + nodeset = new_nodeset node_types = ELEMENTS when :ancestor Index: test/rexml/test_jaxen.rb =================================================================== --- test/rexml/test_jaxen.rb (revision 63082) +++ test/rexml/test_jaxen.rb (revision 63083) @@ -18,9 +18,9 @@ module REXMLTests https://github.com/ruby/ruby/blob/trunk/test/rexml/test_jaxen.rb#L18 def test_contents ; process_test_case("contents") ; end def test_defaultNamespace ; process_test_case("defaultNamespace") ; end def test_fibo ; process_test_case("fibo") ; end - def _test_id ; process_test_case("id") ; end - def _test_jaxen24 ; process_test_case("jaxen24") ; end - def _test_lang ; process_test_case("lang") ; end + def test_id ; process_test_case("id") ; end + def test_jaxen24 ; process_test_case("jaxen24") ; end + def test_lang ; process_test_case("lang") ; end def _test_message ; process_test_case("message") ; end def _test_moreover ; process_test_case("moreover") ; end def _test_much_ado ; process_test_case("much_ado") ; end @@ -111,8 +111,8 @@ module REXMLTests https://github.com/ruby/ruby/blob/trunk/test/rexml/test_jaxen.rb#L111 # processes a tests/document/context/test node ( where @exception is false or doesn't exist ) def process_nominal_test(context, variables, namespaces, test) - select = test.attributes["select"] - matched = XPath.match(context, select, namespaces, variables) + xpath = test.attributes["select"] + matched = XPath.match(context, xpath, namespaces, variables) # might be a test with no count attribute, but nested valueOf elements expected = test.attributes["count"] if expected -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/