Uploaded image for project: 'XalanJ2'
  1. XalanJ2
  2. XALANJ-2330

ToXMLSAXHandler generates startDTD event, but not corresponding endDTD event

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.7
    • None
    • Serialization
    • None
    • Solaris 10, Java 1.4, Xerces 2.8.0, Xalan 2.7.0
    • PatchAvailable

    Description

      The org.apache.xml.serializer.ToXMLSAXHandler generates a startDTD() event on the LexicalHandler for the first element of the document (lines 648-662) to ensure that the document type gets set, however, it doesn't then generate a corresponding endDTD() event after doing so, which leaves the 'state' indeterminate, and behavior relying on the startDTD()/endDTD() pair will break.

      // Handle document type declaration (for first element only)
      if (m_needToOutputDocTypeDecl)
      {
      String doctypeSystem = getDoctypeSystem();
      if (doctypeSystem != null && m_lexHandler != null)

      { String doctypePublic = getDoctypePublic(); if (doctypeSystem != null) m_lexHandler.startDTD( name, doctypePublic, doctypeSystem); }

      m_needToOutputDocTypeDecl = false;
      }

      As a critical example, org.apache.xml.dtm.ref.sax2dtm.SAX2DTM sets a flag, m_insideDTD to true on startDTD() and false on endDTD(); if the flag is true, comments are ommitted from the output (line 2446); if the flag is left hanging by this issue, all comments in the document will be omitted.

      This is a critical problem if you are trying to do something with the comments, such as traditional SSI.

      The fix would be to add an endDTD() event immediately after the startDTD() event in ToXMLSAXHandler#startElement(String,String,String,Attributes).

      I'm not sure if this also effects other handlers.

      Attachments

        1. jira2330.patch1.txt
          1 kB
          Brian Minchau

        Activity

          People

            Unassigned Unassigned
            ellispritchard Ellis Pritchard
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: