filter/qa/unit/textfilterdetect.cxx |   20 ++++++++++++++++++++
 sfx2/source/doc/objstor.cxx         |    6 ++++--
 2 files changed, 24 insertions(+), 2 deletions(-)

New commits:
commit e7cf5e1187c378b680fecefd0d3176de09c55bba
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Wed Jan 27 16:05:54 2021 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Thu Jan 28 16:40:56 2021 +0100

    tdf#123476 filter: Also handle empty ODF
    
    This builds on top of commit ada07f303e7cd1e39c73abe0741aefe7d9d73a57,
    to allow 0-byte ODT, ODS etc.
    
    Possible TODO would be somehow use default template for such empty files,
    getting the template name using SfxObjectFactory::GetStandardTemplate.
    That would enable using 0-byte ODF files as means to "create new document
    at this location from default template" workflow.
    
    Change-Id: I36e07b80f60c42aecdcc6a7357e5bdd18f62e4f7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109989
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    (cherry picked from commit 2854362f429e476d4a1ab4759c6a1f1c04150280)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110061
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/filter/qa/unit/data/empty.odp b/filter/qa/unit/data/empty.odp
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/filter/qa/unit/data/empty.odt b/filter/qa/unit/data/empty.odt
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/filter/qa/unit/textfilterdetect.cxx 
b/filter/qa/unit/textfilterdetect.cxx
index 4e81a333ab71..74d967490ffe 100644
--- a/filter/qa/unit/textfilterdetect.cxx
+++ b/filter/qa/unit/textfilterdetect.cxx
@@ -96,6 +96,26 @@ CPPUNIT_TEST_FIXTURE(TextFilterDetectTest, testEmptyFile)
     // Without the accompanying fix in place, this test would have failed, as 
it was opened in
     // Writer instead.
     
CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.presentation.PresentationDocument"));
+
+    getComponent()->dispose();
+
+    // Now also test ODT
+    aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "empty.odt";
+    getComponent() = loadFromDesktop(aURL);
+    xServiceInfo.set(getComponent(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xServiceInfo.is());
+    // Make sure it opens in Writer.
+    
CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.TextDocument"));
+    getComponent()->dispose();
+
+    // ... and ODP
+    aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "empty.odp";
+    getComponent() = loadFromDesktop(aURL);
+    xServiceInfo.set(getComponent(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT(xServiceInfo.is());
+    // Without the accompanying fix in place, this test would have failed, as 
it was opened in
+    // Writer instead.
+    
CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.presentation.PresentationDocument"));
 }
 }
 
diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index 441ae44c1373..2141a590b212 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -446,7 +446,7 @@ bool SfxObjectShell::InitNew( const uno::Reference< 
embed::XStorage >& xStorage
 
 bool SfxObjectShell::Load( SfxMedium& rMedium )
 {
-    return GeneralInit_Impl( rMedium.GetStorage(), true );
+    return GeneralInit_Impl(rMedium.GetStorage(), 
!tools::isEmptyFileUrl(rMedium.GetName()));
 }
 
 void SfxObjectShell::DoInitUnitTest()
@@ -686,7 +686,9 @@ bool SfxObjectShell::DoLoad( SfxMedium *pMed )
                     bWarnMediaTypeFallback = false;
                 }
 
-                if ( bWarnMediaTypeFallback || 
!xStorage->getElementNames().hasElements() )
+                if (bWarnMediaTypeFallback
+                    || (!tools::isEmptyFileUrl(pMedium->GetName())
+                        && !xStorage->getElementNames().hasElements()))
                     SetError(ERRCODE_IO_BROKENPACKAGE);
             }
             catch( uno::Exception& )
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to