[ 
https://issues.apache.org/jira/browse/MUSE-240?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Dan Jemiolo closed MUSE-240.
----------------------------

    Resolution: Fixed

Applied patch from Rich

> XmlUtils.setNamespaceAttribute allows duplicate namespace declarations
> ----------------------------------------------------------------------
>
>                 Key: MUSE-240
>                 URL: https://issues.apache.org/jira/browse/MUSE-240
>             Project: Muse
>          Issue Type: Bug
>          Components: Utilities - General, QName, and XML
>    Affects Versions: 2.0.0 M1, 2.0.0 M2, 2.0.0, 2.1.0, 2.2.0, 2.3.0
>         Environment: j2sdk1.4.2_13, latest muse from anonsvn repository
>            Reporter: Rich Lucente
>            Assignee: Dan Jemiolo
>            Priority: Minor
>             Fix For: 2.3.0
>
>         Attachments: XmlUtils.java.patch
>
>
> XmlUtils.setNamespaceAttribute allows duplicate namespace declarations 
> because it incorrectly looks for existing namespace declarations in the 
> attributes collection.  It's my understanding that xml namespace declarations 
> are distinct from attributes and do not always appear in the attributes 
> collection.  I've tested the patch below under multiple cases including 
> namespaces bound to the element, namespaces bound to an attribute in the 
> element, default element namespace bindings, and default attribute namespace 
> bindings.  Hope this helps!
> *** original/XmlUtils.java    Sun Jul  1 22:32:07 2007
> --- updated/XmlUtils.java     Sun Jul  1 22:32:23 2007
> ***************
> *** 1836,1846 ****
>       {
>           String attributeName = XMLNS_PREFIX;
>           
> !         if (prefix != null)
> !             attributeName += ':' + prefix;
> !         
> !         if (!element.hasAttribute(attributeName))
> !             element.setAttribute(attributeName, namespaceURI);
>       }
>       
>       /**
> --- 1836,1874 ----
>       {
>           String attributeName = XMLNS_PREFIX;
>           
> !             // correctly handle null or blank prefix
> !             boolean hasPrefix = (prefix != null && prefix.length() > 0);
> ! 
> !             if (hasPrefix)
> !                     attributeName += ':' + prefix;
> ! 
> !             // do not add namespace attribute if matching attribute found, 
> or
> !             // element has matching bound namespace, or attempting to 
> redefine
> !             // element's bound default namespace
> !             if (   element.hasAttribute(attributeName)
> !                     || (   element.getNamespaceURI() != null
> !                             && (   (!hasPrefix && element.getPrefix() == 
> null)
> !                                     || (   element.getPrefix() != null
> !                                             && 
> element.getPrefix().equals(prefix))))) {
> !                     return;
> !             }
> ! 
> !             // do not add namespace attribute if any attributes have the 
> same
> !             // bound prefix or attempting to redefine attribute's bound 
> default
> !             // namespace
> !             NamedNodeMap attrs = element.getAttributes();
> !             for (int index = 0; index < attrs.getLength(); index++) {
> !                     Attr attr = (Attr) attrs.item(index);
> !                     if (   attr.getNamespaceURI() != null
> !                             && (   (!hasPrefix && attr.getPrefix() == null)
> !                                     || (   attr.getPrefix() != null
> !                                             && 
> attr.getPrefix().equals(prefix)))) {
> !                             return;
> !                     }
> !             }
> ! 
> !             // otherwise, add unique namespace
> !             element.setAttribute(attributeName, namespaceURI);
>       }
>       
>       /**

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to