SABITHSAHEB opened a new pull request, #304:
URL: https://github.com/apache/commons-jxpath/pull/304

   Thanks for your contribution to [Apache 
Commons](https://commons.apache.org/)! Your help is appreciated!
   
   Before you push a pull request, review this list:
   
   - [x] Read the [contribution guidelines](CONTRIBUTING.md) for this project.
   - [x] Read the [ASF Generative Tooling 
Guidance](https://www.apache.org/legal/generative-tooling.html) if you use 
Artificial Intelligence (AI).
   - [x] I used AI to create any part of, or all of, this pull request. Which 
AI tool was used to create this pull request, and to what extent did it 
contribute?
   - [x] Run a successful build using the default 
[Maven](https://maven.apache.org/) goal with `mvn`; that's `mvn` on the command 
line by itself.
   - [x] Write unit tests that match behavioral changes, where the tests fail 
if the changes to the runtime are not applied. This may not always be possible, 
but it is a best practice.
   - [x] Write a pull request description that is detailed enough to understand 
what the pull request does, how, and why.
   - [x] Each commit in the pull request should have a meaningful subject line 
and body. Note that a maintainer may squash commits during the merge process.
   
   `DOMAttributeIterator.testAttr` accepts a prefixed attribute name test when 
the attribute's prefix string equals the test prefix, and when the prefixes 
differ it resolves the test prefix against the document instead of the 
expression context. It handles `@p:*` and the fallback in `getAttribute` when 
`getAttributeNodeNS` finds nothing for `@p:name`, so on the DOM model a 
namespace registered with `JXPathContext.registerNamespace` is not honored for 
attributes. With `p` registered as `urn:trusted` and the document `<doc 
xmlns:p="urn:other"><a p:role="admin"/></doc>`, `count(/doc/a/@p:role)` and 
`count(/doc/a/@p:*)` are both 1 on DOM. They are 0 on JDOM, where 
`JDOMAttributeIterator` compares namespace URIs, which is also what DOM element 
name tests do. On a DOM parsed without namespace awareness `getAttributeNodeNS` 
never matches, so the fallback always runs and `@p:role` can return the foreign 
`p:role` even when the element also carries the attribute in `urn:trusted`.
   
   The registered binding is how an application tells its own attributes apart 
from foreign ones in a document it did not write, so this is a namespace 
confusion: a schema with `<xs:anyAttribute namespace="##other"/>` accepts 
`p:role` in any other namespace, and JXPath then reads it as the application's 
attribute. `testAttr` now resolves the test prefix through the context 
`NamespaceResolver`, the same lookup `getAttribute` already uses, and compares 
URIs. A prefix the context cannot resolve still falls back to the document, and 
an undeclared prefix on a non-namespace-aware DOM still matches by name as 
`DOMNodePointer.testNode` does for elements, so lookups that rely on 
document-declared prefixes are unchanged. The new 
`AbstractXMLModelTest.testNamespaceMappingAttribute` runs for both models; on 
DOM it fails without the change (`expected: <0.0> but was: <1.0>`) and passes 
with it, and JDOM passes either way. The default `mvn` build passes on JDK 21.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to