dbertoni    2003/02/06 18:02:37

  Modified:    c/src/XSLT OutputContextStack.cpp OutputContextStack.hpp
                        XSLTEngineImpl.cpp
  Log:
  Make sure CDATA section stack is initialized properly and that the stack is 
not consulted when generated RTFs.  Fixes bugzilla 16853.
  
  Revision  Changes    Path
  1.3       +8 -1      xml-xalan/c/src/XSLT/OutputContextStack.cpp
  
  Index: OutputContextStack.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/OutputContextStack.cpp,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- OutputContextStack.cpp    25 Nov 2002 18:11:52 -0000      1.2
  +++ OutputContextStack.cpp    7 Feb 2003 02:02:36 -0000       1.3
  @@ -70,7 +70,8 @@
   
   OutputContextStack::OutputContextStack() :
        m_stack(1),
  -     m_stackPosition(m_stack.begin())
  +     m_stackPosition(m_stack.begin()),
  +     m_stackSize(0)
   {
        // m_stack is initialized to a size of 1, so that
        // we always have a dummy entry at the beginning
  @@ -90,6 +91,7 @@
   OutputContextStack::pushContext(FormatterListener*   theListener)
   {
        ++m_stackPosition;
  +     ++m_stackSize;
   
        if (m_stackPosition == m_stack.end())
        {
  @@ -116,6 +118,7 @@
        theCurrentContext.reset();
   
        --m_stackPosition;
  +     --m_stackSize;
   }
   
   
  @@ -128,6 +131,8 @@
        OutputContextStackType(1).swap(m_stack);
   
        m_stackPosition = m_stack.begin();
  +
  +     m_stackSize = 0;
   }
   
   
  @@ -139,6 +144,8 @@
        {
                popContext();
        }
  +
  +     assert(size() == 0);
   }
   
   
  
  
  
  1.4       +5 -1      xml-xalan/c/src/XSLT/OutputContextStack.hpp
  
  Index: OutputContextStack.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/OutputContextStack.hpp,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- OutputContextStack.hpp    25 Nov 2002 18:11:52 -0000      1.3
  +++ OutputContextStack.hpp    7 Feb 2003 02:02:36 -0000       1.4
  @@ -213,7 +213,9 @@
        {
                // Since we always keep one dummy entry at the beginning,
                // subtract one from the size
  -             return m_stack.size() - 1;
  +             assert(m_stackSize == 
size_type(OutputContextStackType::const_iterator(m_stackPosition) - 
m_stack.begin()));
  +
  +             return m_stackSize;
        }
   
        bool
  @@ -245,6 +247,8 @@
        OutputContextStackType                          m_stack;
   
        OutputContextStackType::iterator        m_stackPosition;
  +
  +     size_type                                                       
m_stackSize;
   };
   
   
  
  
  
  1.168     +51 -35    xml-xalan/c/src/XSLT/XSLTEngineImpl.cpp
  
  Index: XSLTEngineImpl.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XSLT/XSLTEngineImpl.cpp,v
  retrieving revision 1.167
  retrieving revision 1.168
  diff -u -r1.167 -r1.168
  --- XSLTEngineImpl.cpp        29 Jan 2003 02:19:22 -0000      1.167
  +++ XSLTEngineImpl.cpp        7 Feb 2003 02:02:36 -0000       1.168
  @@ -1424,15 +1424,21 @@
   {
        assert(getFormatterListener() != 0);
        assert(m_executionContext != 0);
  -     assert(m_cdataStack.empty() == true);
   
        if (getHasPendingStartDocument() == false)
        {
  +             assert(m_cdataStack.empty() == true || 
m_outputContextStack.size() != 1);
  +
                m_resultNamespacesStack.pushContext();
   
                setHasPendingStartDocument(true);
   
                setMustFlushPendingStartDocument(false);
  +
  +             if (m_hasCDATASectionElements == true)
  +             {
  +                     m_cdataStack.push_back(false);
  +             }
        }
        else if (getMustFlushPendingStartDocument() == true)
        {
  @@ -1458,7 +1464,6 @@
   {
        assert(getFormatterListener() != 0);
        assert(m_executionContext != 0);
  -     assert(m_cdataStack.empty() == true);
   
        setMustFlushPendingStartDocument(true);
   
  @@ -1473,6 +1478,12 @@
                fireGenerateEvent(ge);
        }
   
  +     if (m_hasCDATASectionElements == true)
  +     {
  +             m_cdataStack.pop_back();
  +     }
  +     assert(m_cdataStack.empty() == true);
  +
        m_resultNamespacesStack.popContext();
   
        assert(m_resultNamespacesStack.empty() == true);
  @@ -2536,53 +2547,58 @@
   
        bool    fResult = false;
   
  -     const XalanDOMString::size_type         indexOfNSSep = 
indexOf(elementName, XalanUnicode::charColon);
  -
  -     if(indexOfNSSep == length(elementName))
  +     // We only want to worry about cdata-section-elements when we're 
serializing the
  +     // result tree, which is only when the output context is 1.
  +     if (m_outputContextStack.size() == 1)
        {
  -             const XalanDOMString* const             elemNS =
  -                                     
getResultNamespaceForPrefix(s_emptyString);
  +             const XalanDOMString::size_type         indexOfNSSep = 
indexOf(elementName, XalanUnicode::charColon);
   
  -             if (elemNS != 0)
  +             if(indexOfNSSep == length(elementName))
                {
  -                     fResult = 
m_stylesheetRoot->isCDATASectionElementName(XalanQNameByReference(*elemNS, 
elementName));
  +                     const XalanDOMString* const             elemNS =
  +                                             
getResultNamespaceForPrefix(s_emptyString);
  +
  +                     if (elemNS != 0)
  +                     {
  +                             fResult = 
m_stylesheetRoot->isCDATASectionElementName(XalanQNameByReference(*elemNS, 
elementName));
  +                     }
  +                     else
  +                     {
  +                             fResult = 
m_stylesheetRoot->isCDATASectionElementName(XalanQNameByReference(s_emptyString,
 elementName));
  +                     }
                }
                else
                {
  -                     fResult = 
m_stylesheetRoot->isCDATASectionElementName(XalanQNameByReference(s_emptyString,
 elementName));
  -             }
  -     }
  -     else
  -     {
  -             typedef StylesheetExecutionContext::GetAndReleaseCachedString   
GetAndReleaseCachedString;
  +                     typedef 
StylesheetExecutionContext::GetAndReleaseCachedString   
GetAndReleaseCachedString;
   
  -             GetAndReleaseCachedString       
elemLocalNameGuard(*m_executionContext);
  -             GetAndReleaseCachedString       
prefixGuard(*m_executionContext);
  +                     GetAndReleaseCachedString       
elemLocalNameGuard(*m_executionContext);
  +                     GetAndReleaseCachedString       
prefixGuard(*m_executionContext);
   
  -             XalanDOMString&         elemLocalName = 
elemLocalNameGuard.get();
  -             XalanDOMString&         prefix = prefixGuard.get();
  +                     XalanDOMString&         elemLocalName = 
elemLocalNameGuard.get();
  +                     XalanDOMString&         prefix = prefixGuard.get();
   
  -             substring(elementName, prefix, 0, indexOfNSSep);
  -             substring(elementName, elemLocalName, indexOfNSSep + 1);
  +                     substring(elementName, prefix, 0, indexOfNSSep);
  +                     substring(elementName, elemLocalName, indexOfNSSep + 1);
   
  -             if(equals(prefix, DOMServices::s_XMLString))
  -             {
  -                     fResult =
  -                                     
m_stylesheetRoot->isCDATASectionElementName(XalanQNameByReference(DOMServices::s_XMLNamespaceURI,
 elemLocalName));
  -             }
  -             else
  -             {
  -                     const XalanDOMString* const             elemNS =
  -                             getResultNamespaceForPrefix(prefix);
  -
  -                     if(elemNS == 0)
  +                     if(equals(prefix, DOMServices::s_XMLString))
                        {
  -                             error("Prefix must resolve to a namespace: " + 
prefix);
  +                             fResult =
  +                                             
m_stylesheetRoot->isCDATASectionElementName(XalanQNameByReference(DOMServices::s_XMLNamespaceURI,
 elemLocalName));
                        }
                        else
                        {
  -                             fResult =
  -                                             
m_stylesheetRoot->isCDATASectionElementName(XalanQNameByReference(*elemNS, 
elemLocalName));
  +                             const XalanDOMString* const             elemNS =
  +                                     getResultNamespaceForPrefix(prefix);
  +
  +                             if(elemNS == 0)
  +                             {
  +                                     error("Prefix must resolve to a 
namespace: " + prefix);
  +                             }
  +                             else
  +                             {
  +                                     fResult =
  +                                                     
m_stylesheetRoot->isCDATASectionElementName(XalanQNameByReference(*elemNS, 
elemLocalName));
  +                             }
                        }
                }
        }
  
  
  

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

Reply via email to