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

Converting an empty node set to a number should return NaN #96

Open
guillaumebrunerie opened this issue Apr 8, 2024 · 1 comment
Open
Labels

Comments

@guillaumebrunerie
Copy link
Contributor

The expression number(//non-existent-node) should evaluate to NaN but it currently evaluates to 0: I verified this by adding the following two tests which should pass, but they fail:

test_xpath_eval(t, empty_example, `number(//non-existent-node) = 0`, false)
assertTrue(t, math.IsNaN(MustCompile(`number(//non-existent-node)`).Evaluate(createNavigator(empty_example)).(float64)))

This creates issues for instance with a document as follows

<data>
    <item v="1"/>
    <item v="2"/>
</data>

The query //item[@v = preceding-sibling::item/@v + 1] should return only the second item, but returns both instead. See http://xpather.com/atHhzd0d for an interactive example confirming that only the second item should match.

Looking at the spec, it says that

  • number(node-set) should first convert the node set to a string,
  • string(node-set) should return the empty string if the node set is empty,
  • number("") should return NaN.
@zhengchun
Copy link
Contributor

the //item[@v = preceding-sibling::item/@v + 1] is a bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants