Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8049842

Incorrect XML from DOMSerializerImpl / BaseMarkupSerializer

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 7u51
    • Fix Version/s: tbd
    • Component/s: xml
    • Labels:
    • Subcomponent:
    • Understanding:
      Cause Known
    • CPU:
      x86_64
    • OS:
      windows_7

      Description

      FULL PRODUCT VERSION :
      java version "1.7.0_51"
      Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      DOMSerializerImpl creates invalid XML when consecutive CDATA sections are included. A Document created with the following XML:
      <?xml version="1.0" encoding="UTF-8"?><root><![CDATA[]]]]><![CDATA[>]]></root>
      results in invalid XML:
      <?xml version="1.0" encoding="UTF-8"?><root><![CDATA[]]>]]></root>
      when using DOMSerializerImpl.write(...).

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      <?xml version="1.0" encoding="UTF-8"?><root><![CDATA[]]]]><![CDATA[>]]></root>
      ACTUAL -
      <?xml version="1.0" encoding="UTF-8"?><root><![CDATA[]]>]]></root>

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package de.Test;

      import com.sun.org.apache.xerces.internal.dom.DOMOutputImpl;
      import com.sun.org.apache.xml.internal.serialize.DOMSerializerImpl;
      import org.testng.annotations.Test;
      import org.w3c.dom.Document;
      import org.w3c.dom.ls.LSOutput;
      import org.w3c.dom.ls.LSSerializer;
      import org.xml.sax.InputSource;
      import org.xml.sax.SAXException;

      import javax.xml.parsers.DocumentBuilder;
      import javax.xml.parsers.DocumentBuilderFactory;
      import javax.xml.parsers.ParserConfigurationException;
      import java.io.IOException;
      import java.io.StringReader;
      import java.io.StringWriter;
      import java.io.Writer;

      import static org.testng.AssertJUnit.assertEquals;

      public class TestXMLParsing
      {
          @Test
          public void testWrite() throws ParserConfigurationException, IOException, SAXException
          {
              String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<root><![CDATA[]]]]><![CDATA[>]]></root>";
              
              final Writer stringWriter = new StringWriter();
              final LSOutput domOutput = new DOMOutputImpl();
              domOutput.setCharacterStream( stringWriter );
              
              final LSSerializer domSerializer = new DOMSerializerImpl();
              DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
              DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
              
              final Document document = documentBuilder.parse(new InputSource(new StringReader(xml)));
              
              domSerializer.write( document.getDocumentElement(), domOutput );
              assertEquals( xml, stringWriter.toString() );
              // expected: <?xml version="1.0" encoding="UTF-8"?><root><![CDATA[]]]]><![CDATA[>]]></root>
              // actual: <?xml version="1.0" encoding="UTF-8"?><root><![CDATA[]]>]]></root>
          }
      }

      ---------- END SOURCE ----------

        Attachments

          Activity

            People

            Assignee:
            aefimov Aleksej Efimov
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated: