Skip to content

Reject a string, number, or boolean where a node-set is required - #390

Open
adityawrk wants to merge 2 commits into
ruby:masterfrom
adityawrk:fix/xpath-nodeset-required
Open

adityawrk wants to merge 2 commits into
ruby:masterfrom
adityawrk:fix/xpath-nodeset-required

Conversation

@adityawrk

Copy link
Copy Markdown

Fixes #350.

XPath requires a node-set for count(), sum(), local-name(), name(), and namespace-uri(), and for a predicate or step after a value. REXML accepted the other types. local-name(1) returned "", sum("string") returned NaN, and count(1 < 2) raised NoMethodError: undefined method 'size' for true. A step after a non-node-set was dropped or turned into an empty node-set: "string"[1] returned the string, and string(a/b)/c matched nothing.

Those cases now raise TypeError. A node-set is unchanged, including id("a")[1] and id("a")/b, which stay an empty node-set because id() returns one. local-name() with no argument still uses the context node, and a variable that holds a node can still be filtered.

ruby test/run.rb: 866 tests, 2779 assertions.

local-name(1), sum("string"), and count(1 < 2) were accepted
or failed with NoMethodError. A predicate or step after a
string, number, or boolean was ignored or matched nothing.
count(), sum(), local-name(), name(), and namespace-uri()
coerced the wrong type or called a method on it. A predicate
or step after a non-node-set became an empty node-set, so the
expression looked like it matched nothing. Those cases now
raise TypeError. A real node-set, including id(), is unchanged.

Fixes ruby#350

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant