Issue Details (XML | Word | Printable)

Key: XALANJ-2302
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Unassigned
Reporter: Brian Minchau
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
XalanJ2

Prefix collision bug during serialization

Created: 21/Jun/06 02:26 AM   Updated: 17/Oct/06 04:06 PM
Return to search
Component/s: None
Affects Version/s: None
Fix Version/s: None

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works serializer.patch1.txt 2006-06-21 02:57 AM Brian Minchau 2 kB
Issue Links:
Reference

Xalan info: PatchAvailable
Reviewer: Yash Talwar


 Description  « Hide
During work on xalanj-2219, which Henry Zongaro reviewed, he found a related bug where
an attribute added through manipulation of a DOM would cause a prefix collision.

His testcase was similar to the one in xalanj-2219. First create an element named "p:child" in namespace URI "child".
When serialized this element would look like this:
<p:child xmlns:p='child' />

Then to this DOM Element, add an attribute named q:attr with value 'val' and have attribute in the namespace 'moo'.
When serialized this element would look like this:
<p:child xlmns:p='child' q:attr='val' xmlns:q='moo' />

Now to cause the collision have the name of the attribute be 'p:attr'. The prefix p must map to both 'child' and to 'moo'.
The only way out is to NOT use p for one of the prefixes, and to pick a new one that is not mapped, something like this:
<p:child xmlns:p='child' ns0:attr='val' xmlns:ns0='moo' />

Henry's testcase, much like the one in xalanj-2219 is this:
-------------------------------------------------------------------------------
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;
public class j2219b {
    private static final String IDENTITY_XSLT_WITH_INDENT =
            "<xsl:stylesheet version='1.0' " +
            "xmlns:xsl='http://www.w3.org/1999/XSL/Transform' " +
            "xmlns:xalan='http://xml.apache.org/xslt' " +
            "exclude-result-prefixes='xalan'>" +
            "<xsl:output method='xml' indent='yes' xalan:indent-amount='4'/>" +
            "<xsl:template match='@*|node()'>" +
            "<xsl:copy>" +
            "<xsl:apply-templates select='@*|node()'/>" +
            "</xsl:copy>" +
            "</xsl:template>" +
            "</xsl:stylesheet>";
    public static void main(String[] args) throws Exception {
        String data = "<p:root xmlns:p='root'/>";
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        Document doc = dbf.newDocumentBuilder().parse(new InputSource(new StringReader(data)));
        Element e = doc.createElementNS("child", "p:child");
        e.setAttributeNS("moo", "p:attr", "val");
        doc.getDocumentElement().appendChild(e);
        Transformer t = TransformerFactory.newInstance().newTransformer(
                new StreamSource(new StringReader(IDENTITY_XSLT_WITH_INDENT)));
        Source source = new DOMSource(doc);
        Result result = new StreamResult(System.out);
        t.transform(source, result);
    }
}

-------------------------------------------------------------------------------

Now there is a problem. When serialized the same prefix cannot be used

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Brian Minchau made changes - 21/Jun/06 02:45 AM
Field Original Value New Value
Link This issue is related to XALANJ-2219 [ XALANJ-2219 ]
Brian Minchau made changes - 21/Jun/06 02:46 AM
Link This issue relates to XALANJ-2219 [ XALANJ-2219 ]
Brian Minchau added a comment - 21/Jun/06 02:57 AM
Patch to the serializer's NamespaceMappings and ToXMLStream classes, so that
when a prefix collision occurs when adding an attribute, that a totally new prefix is chosen
for the attribute.

This is only done when the same prefix is mapped to a different URI on the same element.

Brian Minchau made changes - 21/Jun/06 02:57 AM
Attachment serializer.patch1.txt [ 12335678 ]
Brian Minchau added a comment - 12/Jul/06 11:56 PM
John Gentilin agreed to review this patch at the bug triage on July 11, 2006

Brian Minchau made changes - 12/Jul/06 11:56 PM
Xalan info [PatchAvailable]
reviewer johnglinux@eyecatching.com
Brian Minchau added a comment - 17/Oct/06 04:04 PM
Per the JIRA triage meeting on Oct 16, 2005, Yash T. agreed to review this patch.

Brian Minchau made changes - 17/Oct/06 04:06 PM
Repository Revision Date User Message
ASF #476350 Fri Nov 17 22:53:23 UTC 2006 minchau Applying the patch ElemLiteralResult.patch.txt in XALANJ-2302
which changes two fields from Vector to ArrayList to unsynchronize
them to run faster in multi-threaded mode.

Thanks to Toadie for the patch.
Files Changed
MODIFY /xalan/java/trunk/src/org/apache/xalan/templates/ElemLiteralResult.java