filter/qa/unit/textfilterdetect.cxx | 20 ++++++++++++++++++++ filter/source/textfilterdetect/filterdetect.cxx | 6 +++++- sfx2/source/doc/objstor.cxx | 10 +++++++++- 3 files changed, 34 insertions(+), 2 deletions(-)
New commits: commit da88d0e570493cc6b0f56744bfbc00d829b26ee7 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Tue Dec 21 14:31:34 2021 +0100 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Sat Dec 25 06:48:11 2021 +0100 filter: try to detect 0-byte DOC files based on extension Commit ae1f51b4888a3aa14837ac6e4083f33b2176ca45 (tdf#123476 filter: try to detect 0-byte files based on extension, 2020-10-28), already implemented this UNO-based import filters, do the same for built-in filters as well. Another problem in filter/ was to pick the WW6 filter for .doc -- require export+preferred support in the filter to get WW8 instead. An additional filter that may kick in is MS Word 2003 XML: this is avoided by requiring "preferred". (cherry picked from commit e519d7465f38367205b37bc80f0244029e352306) Conflicts: filter/qa/unit/textfilterdetect.cxx Change-Id: I46e280beb5341213b0fe7a09a549b52c0c1ea3f6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127296 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127432 diff --git a/filter/qa/unit/data/empty.doc b/filter/qa/unit/data/empty.doc new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/filter/qa/unit/textfilterdetect.cxx b/filter/qa/unit/textfilterdetect.cxx index 74d967490ffe..4083610b0736 100644 --- a/filter/qa/unit/textfilterdetect.cxx +++ b/filter/qa/unit/textfilterdetect.cxx @@ -116,6 +116,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(); + + // ... and DOC + aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "empty.doc"; + // Without the accompanying fix in place, this test would have failed, the import filter aborted + // loading. + getComponent() = loadFromDesktop(aURL); + xServiceInfo.set(getComponent(), uno::UNO_QUERY); + CPPUNIT_ASSERT(xServiceInfo.is()); + CPPUNIT_ASSERT(xServiceInfo->supportsService("com.sun.star.text.TextDocument")); + uno::Reference<frame::XModel> xModel(getComponent(), uno::UNO_QUERY); + uno::Sequence<beans::PropertyValue> aArgs = xModel->getArgs(); + comphelper::SequenceAsHashMap aMap(aArgs); + OUString aFilterName; + aMap["FilterName"] >>= aFilterName; + // Without the accompanying fix in place, this test would have failed with: + // - Expected: MS Word 97 + // - Actual : MS WinWord 6.0 + // i.e. opening worked, but saving back failed instead of producing a WW8 binary file. + CPPUNIT_ASSERT_EQUAL(OUString("MS Word 97"), aFilterName); } } diff --git a/filter/source/textfilterdetect/filterdetect.cxx b/filter/source/textfilterdetect/filterdetect.cxx index 1f5080ad0951..4a6314c9224a 100644 --- a/filter/source/textfilterdetect/filterdetect.cxx +++ b/filter/source/textfilterdetect/filterdetect.cxx @@ -149,7 +149,11 @@ bool HandleEmptyFileUrlByExtension(MediaDescriptor& rMediaDesc, const OUString& return false; } - std::shared_ptr<const SfxFilter> pFilter(SfxFilterMatcher().GetFilter4Extension(rExt)); + // Requiring the export+preferred flags helps to find the relevant filter, e.g. .doc -> WW8 (and + // not WW6 or Mac_Word). + SfxFilterFlags nMust + = SfxFilterFlags::IMPORT | SfxFilterFlags::EXPORT | SfxFilterFlags::PREFERED; + std::shared_ptr<const SfxFilter> pFilter(SfxFilterMatcher().GetFilter4Extension(rExt, nMust)); if (!pFilter) { return false; diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx index 49d90e54c599..abdb402e507e 100644 --- a/sfx2/source/doc/objstor.cxx +++ b/sfx2/source/doc/objstor.cxx @@ -774,7 +774,15 @@ bool SfxObjectShell::DoLoad( SfxMedium *pMed ) } else { - bOk = ConvertFrom(*pMedium); + if (tools::isEmptyFileUrl(pMedium->GetName())) + { + // The import filter would fail with empty input. + bOk = true; + } + else + { + bOk = ConvertFrom(*pMedium); + } InitOwnModel_Impl(); } }