Skip to content

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

@guillaumebrunerie

Description

@guillaumebrunerie

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions