From 97fa7024ce608b7908aca369e8c643a5de9ebf78 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Fri, 2 Jun 2017 10:57:23 +0200 Subject: Related: tdf#108269 oox: allow recovering broken DOCM files The content type inside an OOXML file differs for DOCX and DOCM. These must be in sync with the file extension, otherwise MSO refuses to open the file. We used to always write the DOCX content-type even for files which had the DOCM extension. Allow users to recover those broken files by detecting a "has docm extension but docx content-type" file as docm, so re-saving it will produce output that's accepted by MSO as well. Change-Id: I7d60c6f6c1d0421e95b3dc9e8fff617f101919f5 Reviewed-on: https://gerrit.libreoffice.org/38342 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- sw/qa/extras/ooxmlexport/data/bad.docm | Bin 0 -> 9672 bytes sw/qa/extras/ooxmlexport/ooxmlexport9.cxx | 11 +++++++++++ 2 files changed, 11 insertions(+) create mode 100644 sw/qa/extras/ooxmlexport/data/bad.docm (limited to 'sw') diff --git a/sw/qa/extras/ooxmlexport/data/bad.docm b/sw/qa/extras/ooxmlexport/data/bad.docm new file mode 100644 index 000000000000..b1e83220aa83 Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/bad.docm differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx index 9d1a5e161fcc..0191b8a38023 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx @@ -24,6 +24,9 @@ #include #include +#include +#include + class Test : public SwModelTestBase { public: @@ -82,6 +85,14 @@ DECLARE_SW_ROUNDTRIP_TEST(testDocmSave, "hello.docm", nullptr, DocmTest) "application/vnd.ms-word.document.macroEnabled.main+xml"); } +DECLARE_SW_ROUNDTRIP_TEST(testBadDocm, "bad.docm", nullptr, DocmTest) +{ + SwXTextDocument* pTextDoc = dynamic_cast(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + // This was 'MS Word 2007 XML', broken docm files were not recognized. + CPPUNIT_ASSERT_EQUAL(OUString("MS Word 2007 XML VBA"), pTextDoc->GetDocShell()->GetMedium()->GetFilter()->GetName()); +} + DECLARE_OOXMLEXPORT_TEST(testTdf92045, "tdf92045.docx") { // This was true, resulted in setting the blinking font effect. -- cgit