This is an automated email from the ASF dual-hosted git repository.

asf-gitbox-commits pushed a commit to branch ms-odrawxml
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit e2dffc7460ae48c6fdc124acebfda8463b498298
Author: Pedro Giffuni <[email protected]>
AuthorDate: Mon Nov 30 17:37:09 2026 -0500

    oox: repair MCE dispatch and compatibility semantics
---
 main/oox/inc/oox/core/mcealternatecontext.hxx      |   6 +
 main/oox/source/core/fragmenthandler2.cxx          |  11 ++
 main/oox/source/core/mcealternatecontext.cxx       | 218 +++++++++++++++------
 main/oox/source/core/mceprocessor.cxx              |   8 +-
 .../oox/source/ppt/presentationfragmenthandler.cxx |   7 +
 5 files changed, 191 insertions(+), 59 deletions(-)

diff --git a/main/oox/inc/oox/core/mcealternatecontext.hxx 
b/main/oox/inc/oox/core/mcealternatecontext.hxx
index 718105a366..1b4868fb2b 100644
--- a/main/oox/inc/oox/core/mcealternatecontext.hxx
+++ b/main/oox/inc/oox/core/mcealternatecontext.hxx
@@ -169,6 +169,12 @@ private:
     void processProcessContent(
         const ::com::sun::star::uno::Reference<
             ::com::sun::star::xml::sax::XFastAttributeList >& rAttribs );
+
+    /** Returns the namespace URI for a fast token, or empty if unknown. */
+    ::rtl::OUString getNamespaceForToken( sal_Int32 nToken ) const;
+
+    /** Returns the local name for a fast token, or empty if unknown. */
+    ::rtl::OUString getLocalNameForToken( sal_Int32 nToken ) const;
 };
 
 } // namespace core
diff --git a/main/oox/source/core/fragmenthandler2.cxx 
b/main/oox/source/core/fragmenthandler2.cxx
index 7ab330a9f2..3341b6d05c 100644
--- a/main/oox/source/core/fragmenthandler2.cxx
+++ b/main/oox/source/core/fragmenthandler2.cxx
@@ -62,12 +62,21 @@ void SAL_CALL FragmentHandler2::endDocument()
 Reference< XFastContextHandler > SAL_CALL 
FragmentHandler2::createFastChildContext(
         sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs )
 {
+    // First, try MCE interception from base class (FragmentHandler).
+    // This handles mc:AlternateContent and delegates to MceAlternateContext.
+    Reference< XFastContextHandler > xMce = 
FragmentHandler::createFastChildContext( nElement, rxAttribs );
+    if ( xMce.is() )
+        return xMce;
+
+    // Fallback: normal FragmentHandler2 context creation via onCreateContext.
     return implCreateChildContext( nElement, rxAttribs );
 }
 
 void SAL_CALL FragmentHandler2::startFastElement(
         sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs )
 {
+    // Call base class to maintain namespace stack for MCE prefix resolution.
+    FragmentHandler::startFastElement( nElement, rxAttribs );
     implStartElement( nElement, rxAttribs );
 }
 
@@ -78,6 +87,8 @@ void SAL_CALL FragmentHandler2::characters( const OUString& 
rChars )
 
 void SAL_CALL FragmentHandler2::endFastElement( sal_Int32 nElement )
 {
+    // Call base class to maintain namespace stack for MCE prefix resolution.
+    FragmentHandler::endFastElement( nElement );
     implEndElement( nElement );
 }
 
diff --git a/main/oox/source/core/mcealternatecontext.cxx 
b/main/oox/source/core/mcealternatecontext.cxx
index 6c8a248cfa..e108a3164f 100644
--- a/main/oox/source/core/mcealternatecontext.cxx
+++ b/main/oox/source/core/mcealternatecontext.cxx
@@ -26,12 +26,22 @@
 #include <com/sun/star/xml/sax/XFastAttributeList.hpp>
 #include <rtl/ustring.hxx>
 #include "oox/token/tokens.hxx"
+#include "oox/token/namespacemap.hxx"
+#include "oox/core/fasttokenhandler.hxx"
 
 namespace oox {
 namespace core {
 
 // ============================================================================
 
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::xml::sax;
+
+using ::rtl::OUString;
+
+// ============================================================================
+
 OOX_DLLPUBLIC MceAlternateContext::MceAlternateContext(
     const ::com::sun::star::uno::Reference<
         ::com::sun::star::xml::sax::XFastContextHandler >& xDelegate ) :
@@ -97,8 +107,22 @@ void SAL_CALL MceAlternateContext::startFastElement(
 
     // Non-MCE element inside selected branch - forward to delegate
     if ( mbInSelectedBranch && mxDelegate.is() )
+    {
+        mxDelegate->startFastElement( Element, Attribs );
+        return;
+    }
+
+    // Non-MCE element outside selected branch: check mc:ProcessContent
+    // Get namespace and local name for this token
+    ::rtl::OUString aNamespaceURI = getNamespaceForToken( Element );
+    ::rtl::OUString aLocalName = getLocalNameForToken( Element );
+    if ( isProcessContentElement( aNamespaceURI, aLocalName ) && 
mxDelegate.is() )
+    {
         mxDelegate->startFastElement( Element, Attribs );
-    // Non-MCE element outside selected branch - discard
+        return;
+    }
+
+    // Non-MCE element outside selected branch and not in ProcessContent - 
discard
 }
 
 void SAL_CALL MceAlternateContext::startUnknownElement(
@@ -185,12 +209,24 @@ MceAlternateContext::createFastChildContext(
                 static_cast< XFastContextHandler* >( pMceCtx ) );
     }
 
+    // Non-MCE element inside selected branch - forward to delegate
     if ( mbInSelectedBranch && mxDelegate.is() )
         return mxDelegate->createFastChildContext( Element, Attribs );
+
+    // Non-MCE element outside selected branch: check mc:ProcessContent
+    // Get namespace and local name for this token
+    ::rtl::OUString aNamespaceURI = getNamespaceForToken( Element );
+    ::rtl::OUString aLocalName = getLocalNameForToken( Element );
+    if ( isProcessContentElement( aNamespaceURI, aLocalName ) && 
mxDelegate.is() )
+        return mxDelegate->createFastChildContext( Element, Attribs );
+
+    // Non-MCE element outside selected branch and not in ProcessContent
     return ::com::sun::star::uno::Reference<
         ::com::sun::star::xml::sax::XFastContextHandler >();
 }
 
+// ----------------------------------------------------------------------------
+
 ::com::sun::star::uno::Reference<
     ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL
 MceAlternateContext::createUnknownChildContext(
@@ -201,6 +237,18 @@ MceAlternateContext::createUnknownChildContext(
 {
     if ( mbInSelectedBranch && mxDelegate.is() )
         return mxDelegate->createUnknownChildContext( Namespace, Name, Attribs 
);
+
+    // Unknown element outside selected branch: check mc:Ignorable and 
mc:ProcessContent
+    if ( isIgnorableNamespace( Namespace ) &&
+         !isProcessContentElement( Namespace, Name ) )
+    {
+        return ::com::sun::star::uno::Reference<
+            ::com::sun::star::xml::sax::XFastContextHandler >(); // Skip
+    }
+
+    if ( mxDelegate.is() )
+        return mxDelegate->createUnknownChildContext( Namespace, Name, Attribs 
);
+
     return ::com::sun::star::uno::Reference<
         ::com::sun::star::xml::sax::XFastContextHandler >();
 }
@@ -213,6 +261,39 @@ void SAL_CALL MceAlternateContext::characters( const 
::rtl::OUString& aChars )
 
 // ----------------------------------------------------------------------------
 
+void MceAlternateContext::pushNamespaces(
+    const ::com::sun::star::uno::Reference<
+        ::com::sun::star::xml::sax::XFastAttributeList >& rAttribs )
+{
+    ::rtl::OUString aRequires;
+    std::vector< std::pair< ::rtl::OUString, ::rtl::OUString > > aMap =
+        MceProcessor::extractNamespaceDeclarations( rAttribs, aRequires );
+    maNamespaceStack.push_back( aMap );
+}
+
+void MceAlternateContext::popNamespaces()
+{
+    if ( !maNamespaceStack.empty() )
+        maNamespaceStack.pop_back();
+}
+
+::rtl::OUString MceAlternateContext::resolvePrefix(
+    const ::rtl::OUString& rPrefix ) const
+{
+    // Search from top of stack (most local) to bottom (most global).
+    for ( auto it = maNamespaceStack.rbegin(); it != maNamespaceStack.rend(); 
++it )
+    {
+        for ( const auto& rPair : *it )
+        {
+            if ( rPair.first == rPrefix )
+                return rPair.second;
+        }
+    }
+    return ::rtl::OUString(); // Empty = unresolved
+}
+
+// ----------------------------------------------------------------------------
+
 void MceAlternateContext::implEvaluateChoice(
     const ::com::sun::star::uno::Reference<
         ::com::sun::star::xml::sax::XFastAttributeList >& rAttribs )
@@ -262,47 +343,16 @@ void MceAlternateContext::implEvaluateChoice(
     }
 }
 
+// ----------------------------------------------------------------------------
+
 ::com::sun::star::uno::Reference<
-    ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL
-MceAlternateContext::implCreateNullContext()
+    ::com::sun::star::xml::sax::XFastContextHandler > 
MceAlternateContext::implCreateNullContext()
 {
+    // Return a null context that discards all events.
     return ::com::sun::star::uno::Reference<
         ::com::sun::star::xml::sax::XFastContextHandler >();
 }
 
-// ----------------------------------------------------------------------------
-
-OOX_DLLPUBLIC void MceAlternateContext::pushNamespaces(
-    const ::com::sun::star::uno::Reference<
-        ::com::sun::star::xml::sax::XFastAttributeList >& rAttribs )
-{
-    std::vector< std::pair< ::rtl::OUString, ::rtl::OUString > > aMap;
-    ::rtl::OUString aRequires;
-    aMap = MceProcessor::extractNamespaceDeclarations( rAttribs, aRequires );
-    maNamespaceStack.push_back( aMap );
-}
-
-void MceAlternateContext::popNamespaces()
-{
-    if ( !maNamespaceStack.empty() )
-        maNamespaceStack.pop_back();
-}
-
-::rtl::OUString MceAlternateContext::resolvePrefix(
-    const ::rtl::OUString& rPrefix ) const
-{
-    // Search from top of stack (most local) to bottom (most global).
-    for ( auto it = maNamespaceStack.rbegin(); it != maNamespaceStack.rend(); 
++it )
-    {
-        for ( const auto& rPair : *it )
-        {
-            if ( rPair.first == rPrefix )
-                return rPair.second;
-        }
-    }
-    return ::rtl::OUString(); // Empty = unresolved
-}
-
 bool MceAlternateContext::isIgnorableNamespace( const ::rtl::OUString& 
rNamespaceURI ) const
 {
     for ( const auto& rNs : maIgnorableNamespaces )
@@ -317,9 +367,26 @@ bool MceAlternateContext::isProcessContentElement(
     const ::rtl::OUString& rNamespaceURI,
     const ::rtl::OUString& rLocalName ) const
 {
+    ::rtl::OUString aWildcardStar = ::rtl::OUString::createFromAscii( "*" );
     for ( const auto& rPair : maProcessContentElements )
     {
-        if ( rPair.first == rNamespaceURI && rPair.second == rLocalName )
+        const ::rtl::OUString& rStoredNS = rPair.first;
+        const ::rtl::OUString& rStoredLocal = rPair.second;
+
+        // Exact match
+        if ( rStoredNS == rNamespaceURI && rStoredLocal == rLocalName )
+            return true;
+
+        // Wildcard: prefix:* (all elements in namespace)
+        if ( rStoredLocal == aWildcardStar && rStoredNS == rNamespaceURI )
+            return true;
+
+        // Wildcard: *:localName (all elements with this local name)
+        if ( rStoredNS == aWildcardStar && rStoredLocal == rLocalName )
+            return true;
+
+        // Wildcard: *:* (all elements)
+        if ( rStoredNS == aWildcardStar && rStoredLocal == aWildcardStar )
             return true;
     }
     return false;
@@ -344,7 +411,6 @@ std::vector< ::rtl::OUString > 
MceAlternateContext::resolvePrefixList(
                                 rRequires[ nPos ] != '\r' && rRequires[ nPos ] 
!= '\n') )
             ++nPos;
         ::rtl::OUString aPrefix = rRequires.copy( nStart, nPos - nStart );
-
         ::rtl::OUString aNamespaceURI = resolvePrefix( aPrefix );
         if ( aNamespaceURI.getLength() > 0 )
             aResult.push_back( aNamespaceURI );
@@ -432,7 +498,8 @@ void MceAlternateContext::processProcessContent(
                         ++nPos;
                     ::rtl::OUString aQName = aValue.copy( nStart, nPos - 
nStart );
 
-                    // Split QName into prefix and local name.
+                    // Split QName into prefix and local name, supporting 
wildcards.
+                    // Wildcard forms: prefix:*, *:localName, *:*
                     ::rtl::OUString aPrefix;
                     ::rtl::OUString aLocalName;
                     sal_Int32 nColon = aQName.indexOf( ':' );
@@ -443,39 +510,74 @@ void MceAlternateContext::processProcessContent(
                     }
                     else
                     {
-                        // No prefix - default namespace (empty prefix)
-                        aPrefix = ::rtl::OUString();
+                        // No prefix - treat as *:localName (all namespaces 
with this local name)
+                        aPrefix = ::rtl::OUString::createFromAscii( "*" );
                         aLocalName = aQName;
                     }
 
-                    // Resolve prefix to namespace URI.
-                    ::rtl::OUString aNamespaceURI = resolvePrefix( aPrefix );
-                    if ( aNamespaceURI.getLength() > 0 )
+                    // Handle wildcard prefix "*"
+                    ::rtl::OUString aNamespaceURI;
+                    ::rtl::OUString aWildcardStar = 
::rtl::OUString::createFromAscii( "*" );
+                    if ( aPrefix == aWildcardStar )
                     {
-                        // Only add if not already present.
-                        bool bFound = false;
-                        for ( const auto& rExisting : maProcessContentElements 
)
+                        aNamespaceURI = aWildcardStar; // Wildcard namespace
+                    }
+                    else
+                    {
+                        // Resolve prefix to namespace URI.
+                        aNamespaceURI = resolvePrefix( aPrefix );
+                        if ( aNamespaceURI.getLength() == 0 )
+                            continue; // Unresolvable prefix, skip
+                    }
+
+                    // Handle wildcard local name "*"
+                    if ( aLocalName == aWildcardStar )
+                        aLocalName = aWildcardStar;
+
+                    // Only add if not already present.
+                    bool bFound = false;
+                    for ( const auto& rExisting : maProcessContentElements )
+                    {
+                        if ( rExisting.first == aNamespaceURI &&
+                             rExisting.second == aLocalName )
                         {
-                            if ( rExisting.first == aNamespaceURI &&
-                                 rExisting.second == aLocalName )
-                            {
-                                bFound = true;
-                                break;
-                            }
+                            bFound = true;
+                            break;
                         }
-                        if ( !bFound )
-                            maProcessContentElements.push_back(
-                                std::make_pair( aNamespaceURI, aLocalName ) );
                     }
+                    if ( !bFound )
+                        maProcessContentElements.push_back(
+                            std::make_pair( aNamespaceURI, aLocalName ) );
                 }
             }
         }
     }
     catch ( ... )
     {
-        // getAttributes() may throw if not supported
+        // getUnknownAttributes() may throw if not supported
     }
 }
 
+// ----------------------------------------------------------------------------
+
+// Helper to get the namespace URI for a fast token.
+::rtl::OUString MceAlternateContext::getNamespaceForToken( sal_Int32 nToken ) 
const
+{
+    const ::oox::NamespaceMap& rMap = ::oox::StaticNamespaceMap::get();
+    ::oox::NamespaceMap::const_iterator it = rMap.find( nToken );
+    if ( it != rMap.end() )
+        return it->second;
+    return ::rtl::OUString();
+}
+
+// Helper to get the local name for a fast token.
+::rtl::OUString MceAlternateContext::getLocalNameForToken( sal_Int32 nToken ) 
const
+{
+    ::oox::core::FastTokenHandler aHandler;
+    return aHandler.getIdentifier( nToken );
+}
+
+// ----------------------------------------------------------------------------
+
 } // namespace core
-} // namespace oox
+} // namespace oox
\ No newline at end of file
diff --git a/main/oox/source/core/mceprocessor.cxx 
b/main/oox/source/core/mceprocessor.cxx
index 58ad0b8de3..1f59c1d557 100644
--- a/main/oox/source/core/mceprocessor.cxx
+++ b/main/oox/source/core/mceprocessor.cxx
@@ -97,9 +97,15 @@ std::vector< std::pair< ::rtl::OUString, ::rtl::OUString > > 
MceProcessor::extra
             {
                 rRequires = rAttr.Value;
             }
+            else if ( rAttr.Name.equalsAsciiL( "xmlns", 5 ) )
+            {
+                // Default namespace declaration: xmlns="..."
+                aMap.push_back( std::make_pair( ::rtl::OUString(), rAttr.Value 
) );
+            }
             else if ( rAttr.Name.getLength() > 6 &&
                       rAttr.Name.match( ::rtl::OUString::createFromAscii( 
"xmlns:" ), 0 ) )
             {
+                // Prefixed namespace declaration: xmlns:prefix="..."
                 ::rtl::OUString aPrefix = rAttr.Name.copy( 6 );
                 aMap.push_back( std::make_pair( aPrefix, rAttr.Value ) );
             }
@@ -118,7 +124,7 @@ bool MceProcessor::isChoiceEligible(
     const std::vector< std::pair< ::rtl::OUString, ::rtl::OUString > >& 
rPrefixMap )
 {
     if ( rRequires.getLength() == 0 )
-        return false; // Empty Requires means no requirements - treat as not 
eligible
+        return true; // Empty Requires means no requirements - always eligible 
per ECMA-376 ยง15.2.2
 
     // Split by whitespace and resolve each prefix
     sal_Int32 nPos = 0;
diff --git a/main/oox/source/ppt/presentationfragmenthandler.cxx 
b/main/oox/source/ppt/presentationfragmenthandler.cxx
index 87af91779a..dc8b9b0d15 100644
--- a/main/oox/source/ppt/presentationfragmenthandler.cxx
+++ b/main/oox/source/ppt/presentationfragmenthandler.cxx
@@ -310,6 +310,13 @@ void PresentationFragmentHandler::endDocument()
 // CT_Presentation
 Reference< XFastContextHandler > 
PresentationFragmentHandler::createFastChildContext( sal_Int32 aElementToken, 
const Reference< XFastAttributeList >& xAttribs )
 {
+       // First, try MCE interception from base class (FragmentHandler).
+       // This handles mc:AlternateContent and delegates to 
MceAlternateContext.
+       Reference< XFastContextHandler > xMce = 
FragmentHandler::createFastChildContext( aElementToken, xAttribs );
+       if ( xMce.is() )
+               return xMce;
+
+       // Fallback: normal PPT context creation.
        Reference< XFastContextHandler > xRet;
        switch( aElementToken )
        {

Reply via email to