coheigea commented on code in PR #3790:
URL: https://github.com/apache/cxf/pull/3790#discussion_r4713205973


##########
core/src/main/java/org/apache/cxf/staxutils/W3CNamespaceContext.java:
##########
@@ -96,11 +96,14 @@ private String getPrefix(Element e, String uri) {
 
                 String val = a.getValue();
                 if (val != null && val.equals(uri)) {
-                    String name = a.getLocalName();
+                    // only namespace declarations bind a prefix
+                    String name = a.getName();
                     if ("xmlns".equals(name)) {
                         return "";
                     }
-                    return name;
+                    if (name.startsWith("xmlns:")) {
+                        return name.substring(6);
+                    }

Review Comment:
   No, that’s intentional: dropping return name; is the fix. With it, any 
attribute whose value matched the URI was returned as the prefix (e.g. 
targetNamespace). Now only xmlns/xmlns:* return; anything else falls through to 
the next attribute and then the parent element, and the method returns null if 
nothing declares the namespace. testGetPrefixIgnoresNonNamespaceAttributes 
fails if the return is put back. I’ll add a comment to make that clearer.



-- 
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