Repository navigation
Fix XPath matching for the predefined XML namespace and empty strings - #398
Conversation
naitoh
left a comment
There was a problem hiding this comment.
Thanks for the PR!
The fixes for both the predefined xml namespace and empty-string predicates look very clean.
One small request: I'd like to avoid introducing a new public constant REXML::Namespace::XML_URI (which is also exposed on REXML::Element and REXML::Attribute since they include REXML::Namespace).
Could you make XML_URI private with private_constant :XML_URI in lib/rexml/namespace.rb and keep Private::XML_PREFIXED_NAMESPACE in lib/rexml/parsers/baseparser.rb as-is?
|
Thanks, @naitoh. |
|
Thanks! |
Fixes #396.
The XML parser already knows the reserved
xmlbinding, 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 andnamespace-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
0but drops a whitespace-only one afternormalize-space(.).Both new tests failed on master (
f073640a). On macOS, Ruby 4.0.1:bundle exec rake testand the frozen-string-literal run each passed (877 tests, 2,798 assertions);bundle exec rake warning:error rdocalso 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.