Skip to content

Node set predicate not working #25

Closed
@jcavalieri

Description

@jcavalieri

Hi,

I'm upgrading Ruby from 2.4.5 to 2.6.5 and the rexml behavior seems to have changed. We actually had some xpaths that were wrong that were working with the previous version. However, in correcting them I'm seeing this issue:

I expect the following example to return just one node.

xml_string = <<EOF
<div>
  <div>
    <test>1</test>
    <test>2</test>
  </div>
  <div>
    <test>1</test>
    <test>2</test>
  </div>
</div>
EOF

xml_doc = REXML::Document.new(xml_string)

nodes = REXML::XPath.match(xml_doc, '(/div/div/test[1])[1]')

It returns two nodes though.

>nodes.count
=> 2
> nodes.map(&:text)
=> ["1", "1"]

From my understanding placing an xpath subexpression in this (...)[1] should only return the first from the node set.

-John

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions