Skip to content

Fix XPath matching for the predefined XML namespace and empty strings - #398

Open
akzarma wants to merge 1 commit into
ruby:masterfrom
akzarma:fix/xpath-xml-namespace-and-predicates
Open

akzarma wants to merge 1 commit into
ruby:masterfrom
akzarma:fix/xpath-xml-namespace-and-predicates

Conversation

@akzarma

@akzarma akzarma commented Dec 2, 2026

Copy link
Copy Markdown

Fixes #396.

The XML parser already knows the reserved xml binding, but XPath was looking it up in each element’s declared namespaces. For <r lang="other" xml:lang="en"/>, //@xml:* with an explicit XML namespace map returned no attributes. The change shares the reserved binding between the parser, the node namespace lookup, and XPath. It also covers lookup by a different expression prefix and namespace-uri(), without adding a synthetic declaration to the document.

The other failure in the issue was independent: Ruby treats an empty string as true. Non-numeric predicates now use XPath’s existing boolean conversion, while numeric predicates still compare against the context position. A regression test keeps a text node containing 0 but drops a whitespace-only one after normalize-space(.).

Both new tests failed on master (f073640a). On macOS, Ruby 4.0.1: bundle exec rake test and the frozen-string-literal run each passed (877 tests, 2,798 assertions); bundle exec rake warning:error rdoc also passed. Other platforms and Ruby versions were not tested locally.

AI assistance: used OpenAI Codex to develop the patch and regression tests and run the checks above.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XPath misses xml:* attributes and treats empty strings as true in predicates

1 participant