package/source/zippackage/ZipPackage.cxx  |   42 ++++++++++++++++++------------
 sw/qa/extras/ooxmlexport/ooxmlexport5.cxx |    2 -
 2 files changed, 27 insertions(+), 17 deletions(-)

New commits:
commit c15ba11a6ce334b2c0279704c379083858260686
Author:     Aron Budea <[email protected]>
AuthorDate: Fri Oct 31 04:54:57 2025 +1030
Commit:     Aron Budea <[email protected]>
CommitDate: Mon Nov 3 13:51:16 2025 +0100

    OOXML: don't always export override entries in [Content_Types].xml
    
    No need to export if it's no different from the default.
    
    Also reorder defaults alphabetically, in same order as
    exported by original document producers (though not all
    of them are always added in MSO, which is not addressed
    in this change).
    
    Change-Id: I8526da5adc068f02e6da072961c82f4e75e3b984
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193224
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>

diff --git a/package/source/zippackage/ZipPackage.cxx 
b/package/source/zippackage/ZipPackage.cxx
index 2f420170c70f..085f5dbd0ad0 100644
--- a/package/source/zippackage/ZipPackage.cxx
+++ b/package/source/zippackage/ZipPackage.cxx
@@ -42,6 +42,7 @@
 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
 #include <com/sun/star/container/XNameContainer.hpp>
 #include <officecfg/Office/Common.hxx>
+#include <comphelper/DirectoryHelper.hxx>
 #include <comphelper/fileurl.hxx>
 #include <comphelper/processfactory.hxx>
 #include <ucbhelper/content.hxx>
@@ -1210,15 +1211,14 @@ void ZipPackage::WriteContentTypes( ZipOutputStream& 
aZipOut, const std::vector<
     pEntry->nCompressedSize = -1;
     pEntry->nTime = ZipOutputStream::getCurrentDosTime();
 
-    // Add default entries, the count must be updated manually when appending.
     // Add at least the standard default entries.
     uno::Sequence< beans::StringPair > aDefaultsSequence
     {
-        { u"xml"_ustr, u"application/xml"_ustr },
-        { u"rels"_ustr, 
u"application/vnd.openxmlformats-package.relationships+xml"_ustr },
-        { u"png"_ustr, u"image/png"_ustr },
+        { u"fntdata"_ustr, u"application/x-fontdata"_ustr },
         { u"jpeg"_ustr, u"image/jpeg"_ustr },
-        { u"fntdata"_ustr, u"application/x-fontdata"_ustr }
+        { u"png"_ustr, u"image/png"_ustr },
+        { u"rels"_ustr, 
u"application/vnd.openxmlformats-package.relationships+xml"_ustr },
+        { u"xml"_ustr, u"application/xml"_ustr }
     };
 
     uno::Sequence< beans::StringPair > aOverridesSequence(aManList.size());
@@ -1226,20 +1226,30 @@ void ZipPackage::WriteContentTypes( ZipOutputStream& 
aZipOut, const std::vector<
     sal_Int32 nOverSeqLength = 0;
     for (const auto& rMan : aManList)
     {
-        OUString aType;
         OSL_ENSURE( rMan[PKG_MNFST_MEDIATYPE].Name == "MediaType" && 
rMan[PKG_MNFST_FULLPATH].Name == "FullPath",
                     "The mediatype sequence format is wrong!" );
+        OUString aType;
         rMan[PKG_MNFST_MEDIATYPE].Value >>= aType;
-        if ( !aType.isEmpty() )
-        {
-            OUString aPath;
-            // only nonempty type makes sense here
-            rMan[PKG_MNFST_FULLPATH].Value >>= aPath;
-            //FIXME: For now we have no way of differentiating defaults from 
others.
-            aOverridesSequenceRange[nOverSeqLength].First = "/" + aPath;
-            aOverridesSequenceRange[nOverSeqLength].Second = aType;
-            ++nOverSeqLength;
-        }
+        if (aType.isEmpty())
+            continue;
+
+        OUString aPath, aExtension;
+        rMan[PKG_MNFST_FULLPATH].Value >>= aPath;
+        (void)comphelper::DirectoryHelper::splitAtLastToken(aPath, '.', 
aExtension);
+
+        // don't add override if same extension and content type exists as 
default
+        const bool bTypeFound
+            = !aExtension.isEmpty()
+              && std::find_if(aDefaultsSequence.begin(), 
aDefaultsSequence.end(),
+                              [&aExtension, &aType](const beans::StringPair& 
defPair)
+                              { return defPair.First == aExtension && 
defPair.Second == aType; })
+                     != aDefaultsSequence.end();
+        if (bTypeFound)
+            continue;
+
+        aOverridesSequenceRange[nOverSeqLength].First = "/" + aPath;
+        aOverridesSequenceRange[nOverSeqLength].Second = aType;
+        ++nOverSeqLength;
     }
     aOverridesSequence.realloc(nOverSeqLength);
 
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
index ea465cd70f43..236892229e05 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport5.cxx
@@ -487,7 +487,7 @@ CPPUNIT_TEST_FIXTURE(Test, testFDO78284)
 {
     loadAndSave("fdo78284.docx");
     xmlDocUniquePtr pXmlDoc = parseExport(u"[Content_Types].xml"_ustr);
-    
assertXPath(pXmlDoc,"/ContentType:Types/ContentType:Override[@PartName='/word/media/OOXDiagramDataRels1_0.png']",
+    
assertXPath(pXmlDoc,"/ContentType:Types/ContentType:Default[@Extension='png']",
                         "ContentType",
                         u"image/png");
 }

Reply via email to