From 7a6f34103de55678241471aef582a5aa24622496 Mon Sep 17 00:00:00 2001 From: kou Date: Sun, 22 Apr 2018 09:38:06 +0000 Subject: rexml: Fix XPath bug of //#{ELEMENT_NAME}[#{POSITION}] The position should be counted for each nodeset but the previous implementation counts position for union-ed nodeset. For example, "/a/*/*[1]" should be matched to "" and "" with the following XML. But the previous implementation just returns only "". * lib/rexml/element.rb (REXML::Attributes#each_attribute): Support Enumerator for no block use. * lib/rexml/element.rb (REXML::Attributes#each): Support Enumerator for no block use. * lib/rexml/functions.rb (REXML::Functions.string): Support NaN again. * lib/rexml/xpath_parser.rb: Re-implement "Step" evaluator. It should evaluate "AxisSpecifier", "NodeTest" and "Predicate" in one step to respect position for each nodeset. * test/rexml/test_jaxen.rb: Enable more tests. Remained tests should be also enabled but it'll not be near future. * test/rexml/xpath/test_base.rb: Fix expected value. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63237 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/rexml/xpath/test_base.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/rexml/xpath/test_base.rb') diff --git a/test/rexml/xpath/test_base.rb b/test/rexml/xpath/test_base.rb index 497bd9fc8f..790dcaea22 100644 --- a/test/rexml/xpath/test_base.rb +++ b/test/rexml/xpath/test_base.rb @@ -713,7 +713,7 @@ module REXMLTests XML d = REXML::Document.new( source ) r = REXML::XPath.match( d, %q{/a/*/*[1]} ) - assert_equal(["1"], + assert_equal(["1", "3"], r.collect {|element| element.attribute("id").value}) end @@ -849,7 +849,7 @@ module REXMLTests EOL d = REXML::Document.new( string ) cs = XPath.match( d, '/a/*/*[1]' ) - assert_equal(["c1"], cs.collect(&:name)) + assert_equal(["c1", "c2"], cs.collect(&:name)) end def test_sum -- cgit v1.2.3