sw/qa/extras/ooxmlexport/data/UnknownStyleInRedline.docx |binary sw/qa/extras/ooxmlexport/ooxmlexport18.cxx | 11 +++++++++++ sw/source/filter/ww8/docxattributeoutput.cxx | 8 +++++--- sw/source/filter/ww8/wrtw8sty.cxx | 3 +-- sw/source/filter/ww8/wrtww8.hxx | 3 +++ 5 files changed, 20 insertions(+), 5 deletions(-)
New commits: commit 22c292a2a9f4f459539d042ad902441a3583c804 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Tue Jan 24 09:37:38 2023 +0300 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Tue Jan 24 09:42:18 2023 +0000 The resolved style name *can* be empty in redlines I assumed otherwise in commit 20adf4683c7d38ad41edac586b897757393c8029 ("tdf#152425 related: don't generate style ids in DocxAttributeOutput::Redline", 2023-01-13). But the string that we try to resolve may come from original file, and so must be treated as arbitrary user input, which may not resolve to a known style. This basically reverts commit 20adf4683c7d38ad41edac586b897757393c8029. Change-Id: Ia6cbce1b9601df2c15edbab653b9b629d52d5ff6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146055 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/sw/qa/extras/ooxmlexport/data/UnknownStyleInRedline.docx b/sw/qa/extras/ooxmlexport/data/UnknownStyleInRedline.docx new file mode 100644 index 000000000000..37457fe1e82b Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/UnknownStyleInRedline.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx index e27a1f085b11..1be945cb9f49 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport18.cxx @@ -309,6 +309,17 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf153128) CPPUNIT_ASSERT_LESS(sal_Int32(30), nFirstLineHeight); } +CPPUNIT_TEST_FIXTURE(Test, testExportingUnknownStyleInRedline) +{ + // This must not fail assertions + loadAndReload("UnknownStyleInRedline.docx"); + // Check that the original unknown style name "UnknownStyle" is roundtripped + // (maybe this is wrong, because Word does not do this). + xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); + assertXPath(pXmlDoc, + "/w:document/w:body/w:p/w:pPr/w:pPrChange/w:pPr/w:pStyle[@w:val='UnknownStyle']"); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index dfdaa4013bb3..01809ae0c0cc 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -3880,9 +3880,11 @@ void DocxAttributeOutput::Redline( const SwRedlineData* pRedlineData) if (auto format = m_rExport.m_rDoc.FindTextFormatCollByName(sParaStyleName)) if (auto slot = m_rExport.m_pStyles->GetSlot(format); slot != 0xfff) sStyleName = m_rExport.m_pStyles->GetStyleId(slot); - // If the style name is empty at this point, this is a bug, meaning that we - // failed to output the style to styles.xml properly - assert(!sStyleName.isEmpty()); + // The resolved style name can be empty at this point, sParaStyleName can be + // an arbitrary string from the original document. + // Note that Word does *not* roundtrip unknown style names in redlines! + if (sStyleName.isEmpty()) + sStyleName = MSWordStyles::CreateStyleId(sParaStyleName); if (!sStyleName.isEmpty()) m_pSerializer->singleElementNS(XML_w, XML_pStyle, FSNS(XML_w, XML_val), sStyleName); } diff --git a/sw/source/filter/ww8/wrtw8sty.cxx b/sw/source/filter/ww8/wrtw8sty.cxx index 9520bc7fae35..2954a94c239c 100644 --- a/sw/source/filter/ww8/wrtw8sty.cxx +++ b/sw/source/filter/ww8/wrtw8sty.cxx @@ -421,8 +421,7 @@ void MSWordStyles::BuildWwNames() } } -/// create style id using only ASCII characters of the style name -static OString CreateStyleId(std::u16string_view aName) +OString MSWordStyles::CreateStyleId(std::u16string_view aName) { OStringBuffer aStyleIdBuf(aName.size()); for (size_t i = 0; i < aName.size(); ++i) diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx index b44575a89bab..cf5d0bfa104b 100644 --- a/sw/source/filter/ww8/wrtww8.hxx +++ b/sw/source/filter/ww8/wrtww8.hxx @@ -1633,6 +1633,9 @@ public: /// Get slot of the style (rFormat). sal_uInt16 GetSlot( const SwFormat* pFormat ) const; + /// create style id using only ASCII characters of the style name + static OString CreateStyleId(std::u16string_view aName); + /// Get styleId of the nSlot-th style (nSlot is its position in m_aStyles). OString const & GetStyleId(sal_uInt16 nSlot) const;