oox/source/core/filterdetect.cxx  |   11 +++++------
 oox/source/core/xmlfilterbase.cxx |   21 ++++++---------------
 test/source/bootstrapfixture.cxx  |    7 +++----
 3 files changed, 14 insertions(+), 25 deletions(-)

New commits:
commit 229997f0d992aecebd337fd67f97d240631afd03
Author:     Justin Luth <[email protected]>
AuthorDate: Wed Dec 3 13:29:42 2025 -0500
Commit:     Miklos Vajna <[email protected]>
CommitDate: Mon Dec 8 14:20:08 2025 +0100

    tdf#165207 xlsx/pptx: always use errata uri in docProps/core.xml
    
    This fixes a longstanding bug that has gone unnoticed
    since nobody saves to the "Office Open XML" filters
    and the problem is only seen in MS Office.
    
    So what does this patch fix?
    Basically, all of the meta-data was not being read by MS Office,
    which primarily means no create/modify dates, subject, title etc.
    Every time we saved to OOXML formats (except OOXML 2007),
    we caused MS Office to be incapable
    of understanding anything in docProps/core.xml.
    Telltale sign: when MS Office round-trips
    with an added docProps/core0.xml.
    
    The spec says that ISO 29500 formats should be using
        officedocuments/2006/relationships/metadata/core-properties
    and thus our untouched 2010-era coding
    specified all of that for export (and more recently for import).
    
    > 2.1.33 Part 1 Section 15.2.11.1, Core File Properties Part
    > The standard specifies a source relationship
    > for the Core File Properties part as follows:
    > .../officedocument/.../core-properties.
    > HOWEVER: Office uses the following source relationship
    > for the Core File Properties part:
    > .../package/.../core-properties.
    
    Thus reality is much different than the spec,
    so throw the spec out the window and always write
        package/2006/relationships/metadata/core-properties
    
    Bug 165207 doesn't affect LO in any way - it only affect MSOffice.
    If there was already a unit test writing out to _rels/.rels
    I would have added a test for this, but since there isn't
    I won't bother since I don't see any value in doing so.
    
    Change-Id: I582448adb568ecb630f2fd64712ce372875f71df
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195014
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <[email protected]>
    (cherry picked from commit de25c6c546afdb9be71bd3326af6a5e3f962edbf)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/195131
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Reviewed-by: Miklos Vajna <[email protected]>

diff --git a/oox/source/core/filterdetect.cxx b/oox/source/core/filterdetect.cxx
index ccd879f4494b..f156d29d0b48 100644
--- a/oox/source/core/filterdetect.cxx
+++ b/oox/source/core/filterdetect.cxx
@@ -167,12 +167,11 @@ void FilterDetectDocHandler::parseRelationship( const 
AttributeList& rAttribs )
 {
     OUString aType = rAttribs.getStringDefaulted( XML_Type);
 
-    // tdf#131936 Remember filter when opening file as 'Office Open XML Text'
-    if 
(aType.startsWithIgnoreAsciiCase("http://schemas.openxmlformats.org/officedocument/2006/relationships/metadata/core-properties";))
-        maOOXMLVariant = OOXMLVariant::ISO_Transitional;
-    else if 
(aType.startsWithIgnoreAsciiCase("http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties";))
-        maOOXMLVariant = OOXMLVariant::ECMA_Transitional;
-    else if 
(aType.startsWithIgnoreAsciiCase("http://purl.oclc.org/ooxml/officeDocument";))
+    // Although the spec says that ISO_Transitional uses the "officedocument" 
URI for core.xml,
+    // MS errata admits that MS Office just uses the old "package" URI from 
ECMA_376_1ST_EDITION.
+    // So core-properties can't be used to identify a non-ECMA_376_1ST_EDITION 
document...
+
+    if 
(aType.startsWithIgnoreAsciiCase("http://purl.oclc.org/ooxml/officeDocument";))
         maOOXMLVariant = OOXMLVariant::ISO_Strict;
 
     if ( aType != 
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument";
 // OOXML Transitional
diff --git a/oox/source/core/xmlfilterbase.cxx 
b/oox/source/core/xmlfilterbase.cxx
index 4869f27015a3..e38c5908dc21 100644
--- a/oox/source/core/xmlfilterbase.cxx
+++ b/oox/source/core/xmlfilterbase.cxx
@@ -682,21 +682,12 @@ writeCoreProperties( XmlFilterBase& rSelf, const 
Reference< XDocumentProperties
         = bRemovePersonalInfo
           && 
!SvtSecurityOptions::IsOptionSet(SvtSecurityOptions::EOption::DocWarnKeepDocUserInfo);
 
-    // Although the spec says that ISOIEC_29500_2008 must use the 
"officedocument" URI,
-    // in MS errata they admit that DOCX just uses the old "package" URI from 
ECMA_376_1ST_EDITION.
-
-    OUString sValue;
-    const bool bDocx = 
dynamic_cast<text::XTextDocument*>(rSelf.getModel().get());
-    if (!bDocx && rSelf.getVersion() == oox::core::ISOIEC_29500_2008)
-    {
-        // The lowercase "officedocument" is intentional and according to the 
spec
-        // (although most other places are written "officeDocument")
-        sValue = 
"http://schemas.openxmlformats.org/officedocument/2006/relationships/metadata/core-properties";;
-    }
-    else
-        sValue = 
"http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties";;
-
-    rSelf.addRelation( sValue, u"docProps/core.xml" );
+    // Although the spec says that ISOIEC_29500_2008 must use the 
"officedocument" URI for core.xml,
+    // MS errata admits that MS Office just uses the old "package" URI from 
ECMA_376_1ST_EDITION.
+    // Tested with Office 2024 - and even "Strict Open XML" uses "package".
+    rSelf.addRelation(
+        
u"http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties"_ustr,
+        u"docProps/core.xml");
     FSHelperPtr pCoreProps = rSelf.openFragmentStreamWithSerializer(
             u"docProps/core.xml"_ustr,
             u"application/vnd.openxmlformats-package.core-properties+xml"_ustr 
);
diff --git a/test/source/bootstrapfixture.cxx b/test/source/bootstrapfixture.cxx
index a34cc7e4473b..34e48bbb16b0 100644
--- a/test/source/bootstrapfixture.cxx
+++ b/test/source/bootstrapfixture.cxx
@@ -166,7 +166,7 @@ OUString filterOut(const OUString& s, std::u16string_view 
excludedSubstr)
     return result;
 }
 
-OUString filterValidationResults(const OUString& s, std::u16string_view 
rFilter)
+OUString filterValidationResults(const OUString& s)
 {
     OUString result = s;
     // In ECMA-376-1 Second Edition, 2008, there is the following restriction 
for oleObj:
@@ -190,11 +190,10 @@ OUString filterValidationResults(const OUString& s, 
std::u16string_view rFilter)
     // But officeotron only knows the old version...
     result = filterOut(result, u"Invalid content was found starting with 
element 'p:pic'. No child element is expected at this point.");
 
-    if (rFilter == u"Office Open XML Text")
     {
         /* While the spec says the core-properties relationship must be
          *     officedocument/2006/relationships/metadata/core-properties
-         * MS Word actually just writes the ECMA-376-1ST EDITION version
+         * MS Office actually just writes the ECMA-376-1ST EDITION version
          * for both ECMA_Transitional and ISO_Transitional formats.
          *
          * officeotron doesn't care that clause 15.2.12.1 fails on all 
MSWord-produced output.
@@ -308,7 +307,7 @@ void test::BootstrapFixture::validate(const OUString& 
rPath, std::u16string_view
 
     if( eFormat == test::OOXML && !aContentOUString.isEmpty() )
     {
-        aContentOUString = filterValidationResults(aContentOUString, rFilter);
+        aContentOUString = filterValidationResults(aContentOUString);
         // check for validation errors here
         sal_Int32 nIndex = aContentOUString.lastIndexOf(grand_total);
         if(nIndex == -1)

Reply via email to