Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node set predicate not working #25

Closed
jcavalieri opened this issue Feb 21, 2020 · 4 comments
Closed

Node set predicate not working #25

jcavalieri opened this issue Feb 21, 2020 · 4 comments

Comments

@jcavalieri
Copy link

jcavalieri commented Feb 21, 2020

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

@jcavalieri
Copy link
Author

I just test with 2.4.5 and I get the result that I expect.

> nodes.count
=> 1

@jcavalieri
Copy link
Author

It also appears to work with 2.5.

@jcavalieri
Copy link
Author

appears to be broken in 2.7 as well

@kou
Copy link
Member

kou commented Feb 22, 2020

Thanks for your report.
This is a bug. This should be fixed.

naitoh added a commit to naitoh/rexml that referenced this issue May 2, 2024
## Why?
Fixed incorrect calculation of position in node set.

See: ruby#25
@kou kou closed this as completed in 06be5cf May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants