# HG changeset patch # User clanger # Date 1486994768 -3600 # Mon Feb 13 15:06:08 2017 +0100 # Node ID 6899aa30ed0e3ef09904bd8fec3a080cb22b7c83 # Parent 412df235a8a229469a2cb9e7bb274d43277077d2 8172974: [JAXP] XALAN: Wrong result when transforming namespace unaware StAX Input diff --git a/src/java.xml/share/classes/com/sun/org/apache/xml/internal/dtm/ref/sax2dtm/SAX2DTM2.java b/src/java.xml/share/classes/com/sun/org/apache/xml/internal/dtm/ref/sax2dtm/SAX2DTM2.java --- a/src/java.xml/share/classes/com/sun/org/apache/xml/internal/dtm/ref/sax2dtm/SAX2DTM2.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xml/internal/dtm/ref/sax2dtm/SAX2DTM2.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved. */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -2024,11 +2024,18 @@ // in case URI and localName are empty, the input is not using the // namespaces feature. Then we should take the part after the last // colon of qName as localName (strip all namespace prefixes) - if ((uri == null || uri.isEmpty()) && - (localName == null || localName.isEmpty())) - { - final int colon = qName.lastIndexOf(':'); - localName = (colon > -1) ? qName.substring(colon + 1) : qName; + // When the URI is empty but localName has colons then we can also + // assume non namespace aware and prefixes can be stripped + if (uri == null || uri.isEmpty()) { + if (localName == null || localName.isEmpty()) { + final int colon = qName.lastIndexOf(':'); + localName = (colon > -1) ? qName.substring(colon + 1) : qName; + } else { + final int colon = localName.lastIndexOf(':'); + if (colon > -1) { + localName = localName.substring(colon + 1); + } + } } int exName = m_expandedNameTable.getExpandedTypeID(uri, localName, @@ -2098,7 +2105,9 @@ attrLocalName = (colon > -1) ? attrQName.substring(colon + 1) : attrQName; } else { final int colon = attrLocalName.lastIndexOf(':'); - attrLocalName = (colon > -1) ? attrLocalName.substring(colon + 1) : attrLocalName; + if (colon > -1) { + attrLocalName = attrLocalName.substring(colon + 1); + } } } diff --git a/test/javax/xml/jaxp/unittest/transform/TransformerTest.java b/test/javax/xml/jaxp/unittest/transform/TransformerTest.java --- a/test/javax/xml/jaxp/unittest/transform/TransformerTest.java +++ b/test/javax/xml/jaxp/unittest/transform/TransformerTest.java @@ -75,7 +75,7 @@ * @run testng/othervm -DrunSecMngr=true transform.TransformerTest * @run testng/othervm transform.TransformerTest * @summary Transformer Tests - * @bug 6272879 6305029 6505031 8150704 8162598 8169112 8169631 8169772 + * @bug 6272879 6305029 6505031 8150704 8162598 8169112 8169631 8169772 8172974 */ @Listeners({jaxp.library.FilePolicy.class}) public class TransformerTest { @@ -399,6 +399,8 @@ // get StAXSource objects XMLInputFactory xif = XMLInputFactory.newInstance(); StAXSource staxSourceWithNS = getStAXSource(xif); + xif.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false); + StAXSource staxSourceWithoutNS = getStAXSource(xif); // print XML/XSL snippets to ease understanding of result printSnippet("Source:", getSourceXml()); @@ -416,12 +418,13 @@ {t, domSourceWithoutNS, "DOMSource without namespace support", 3, 3}, {tFromTemplates, saxSourceWithNS, "SAXSource with namespace support", 0, 1}, {tFromTemplates, saxSourceWithoutNS, "SAXSource without namespace support", 3, 3}, - {t, staxSourceWithNS, "StAXSource with namespace support", 0, 1} + {t, staxSourceWithNS, "StAXSource with namespace support", 0, 1}, + {t, staxSourceWithoutNS, "StAXSource without namespace support", 3, 3} }; } /* - * @bug 8169631 + * @bug 8169631 8172974 * @summary Test combinations of namespace awareness settings on * XSL transformations */