diff options
author | Tor Lillqvist <tml@collabora.com> | 2019-02-19 11:03:20 +0200 |
---|---|---|
committer | Tor Lillqvist <tml@collabora.com> | 2019-02-19 18:02:30 +0100 |
commit | 65559252f138aada7a55d3c5fe0a932a222d13e0 (patch) | |
tree | 583479773c42b1eb8ed4b7c6832e429132ec40ee | |
parent | db32d80b839bf7c161f18d69740bdd6b4aa803ec (diff) |
tdf#110987: Don't mis-detect .doc files as .dot
Also add a unit test for that.
Change-Id: I86c195cebbe12b2bdf498954956db882f6f0d12b
Reviewed-on: https://gerrit.libreoffice.org/68005
Tested-by: Jenkins
Reviewed-by: Tor Lillqvist <tml@collabora.com>
-rw-r--r-- | sw/qa/extras/ww8import/data/tdf110987 | bin | 0 -> 9216 bytes | |||
-rw-r--r-- | sw/qa/extras/ww8import/ww8import.cxx | 13 | ||||
-rw-r--r-- | sw/source/ui/uno/swdetect.cxx | 22 |
3 files changed, 35 insertions, 0 deletions
diff --git a/sw/qa/extras/ww8import/data/tdf110987 b/sw/qa/extras/ww8import/data/tdf110987 Binary files differnew file mode 100644 index 000000000000..16195c0e1579 --- /dev/null +++ b/sw/qa/extras/ww8import/data/tdf110987 diff --git a/sw/qa/extras/ww8import/ww8import.cxx b/sw/qa/extras/ww8import/ww8import.cxx index 9398645f1e16..41b4d34a5edf 100644 --- a/sw/qa/extras/ww8import/ww8import.cxx +++ b/sw/qa/extras/ww8import/ww8import.cxx @@ -17,6 +17,8 @@ #include <editeng/boxitem.hxx> #include <editeng/lrspitem.hxx> #include <editeng/ulspitem.hxx> +#include <sfx2/docfile.hxx> +#include <sfx2/docfilt.hxx> class Test : public SwModelTestBase { @@ -268,6 +270,17 @@ DECLARE_WW8IMPORT_TEST(testTdf122425_2, "tdf122425_2.doc") } } +DECLARE_WW8IMPORT_TEST(testTdf110987, "tdf110987") +{ + // The input document is an empty .doc, but without file name + // extension. Check that it was loaded as a normal .doc document, + // and not a template. + SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + OUString sFilterName = pTextDoc->GetDocShell()->GetMedium()->GetFilter()->GetFilterName(); + CPPUNIT_ASSERT(sFilterName != "MS Word 97 Vorlage"); +} + // tests should only be added to ww8IMPORT *if* they fail round-tripping in ww8EXPORT CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/ui/uno/swdetect.cxx b/sw/source/ui/uno/swdetect.cxx index a87824640c4f..fffceefa2fef 100644 --- a/sw/source/ui/uno/swdetect.cxx +++ b/sw/source/ui/uno/swdetect.cxx @@ -95,7 +95,29 @@ OUString SAL_CALL SwFilterDetect::detect( Sequence< PropertyValue >& lDescriptor { bIsDetected = aStorage->IsContained( "WordDocument" ); if ( bIsDetected && aTypeName.startsWith( "writer_MS_Word_97" ) ) + { bIsDetected = ( aStorage->IsContained("0Table") || aStorage->IsContained("1Table") ); + + // If we are checking the template type, and the document is not a .dot, don't + // mis-detect it. + if ( bIsDetected && aTypeName == "writer_MS_Word_97_Vorlage" ) + { + // Super ugly hack, but we don't want to use the whole WW8Fib thing here in + // the swd library, apparently. We know (do we?) that the "aBits1" byte, as + // the variable is called in WW8Fib::WW8Fib(SvStream&,sal_uInt8,sal_uInt32), + // is at offset 10 in the WordDocument stream. The fDot bit is bit 0x01 of + // that byte. + tools::SvRef<SotStorageStream> xWordDocument = aStorage->OpenSotStream("WordDocument", StreamMode::STD_READ); + xWordDocument->Seek( 10 ); + if ( xWordDocument->Tell() == 10 ) + { + sal_uInt8 aBits1; + xWordDocument->ReadUChar( aBits1 ); + // Check fDot bit + bIsDetected = ((aBits1 & 0x01) == 0x01); + } + } + } } } catch (...) |