sw/qa/filter/ww8/ww8.cxx | 28 +++++++++++++++++++++++++++ sw/source/filter/ww8/docxattributeoutput.cxx | 11 +++++++--- 2 files changed, 36 insertions(+), 3 deletions(-)
New commits: commit e77e25e6ac8d4fafa83cf4d1ebeb53fd719c834c Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Mon Nov 21 20:05:11 2022 +0100 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Wed Dec 14 18:35:31 2022 +0000 tdf#152045 DOCX export: fix empty display text for content control list items Regression from commit f726fbc2699b05199a8dec3055710a7131e0aad6 (tdf#151261 DOCX import: fix dropdown SDT when the item display text is missing, 2022-10-10), the problem was that the correct way to represent "no display value" is not an attribute with empty value but a missing attribute. Change-Id: I25b2bb564444f43d1ca1bf95d1c59b208cb24530 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143048 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmik...@collabora.com> (cherry picked from commit 017c38a9702da0566ac1ce5d758444e5ff25df9d) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143257 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/sw/qa/filter/ww8/ww8.cxx b/sw/qa/filter/ww8/ww8.cxx index ab9e456be695..9268a9943305 100644 --- a/sw/qa/filter/ww8/ww8.cxx +++ b/sw/qa/filter/ww8/ww8.cxx @@ -10,6 +10,10 @@ #include <swmodeltestbase.hxx> #include <com/sun/star/text/XTextDocument.hpp> +#include <docsh.hxx> +#include <formatcontentcontrol.hxx> +#include <unotxdoc.hxx> +#include <wrtsh.hxx> namespace { @@ -81,6 +85,30 @@ CPPUNIT_TEST_FIXTURE(Test, testDocxHyperlinkShape) // assertion failure for not-well-formed XML output): save("Office Open XML Text", maTempFile); } + +CPPUNIT_TEST_FIXTURE(Test, testDocxContentControlDropdownEmptyDisplayText) +{ + // Given a document with a dropdown content control, the only list item has no display text + // (only a value): + mxComponent = loadFromDesktop("private:factory/swriter"); + SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + SwDoc* pDoc(pTextDoc->GetDocShell()->GetDoc()); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->InsertContentControl(SwContentControlType::DROP_DOWN_LIST); + + // When saving to DOCX: + save("Office Open XML Text", maTempFile); + mbExported = true; + + // Then make sure that no display text attribute is written: + xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); + CPPUNIT_ASSERT(pXmlDoc); + // Without the accompanying fix in place, this test would have failed with: + // - XPath '//w:sdt/w:sdtPr/w:dropDownList/w:listItem' unexpected 'displayText' attribute + // i.e. we wrote an empty attribute instead of omitting it. + assertXPathNoAttribute(pXmlDoc, "//w:sdt/w:sdtPr/w:dropDownList/w:listItem", "displayText"); +} } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index e03dd478bb76..206e0cde6478 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -2396,9 +2396,14 @@ void DocxAttributeOutput::WriteContentControlStart() m_pSerializer->startElementNS(XML_w, XML_dropDownList); for (const auto& rItem : m_pContentControl->GetListItems()) { - m_pSerializer->singleElementNS(XML_w, XML_listItem, - FSNS(XML_w, XML_displayText), rItem.m_aDisplayText, - FSNS(XML_w, XML_value), rItem.m_aValue); + rtl::Reference<FastAttributeList> xAttributes = FastSerializerHelper::createAttrList(); + if (!rItem.m_aDisplayText.isEmpty()) + { + // If there is no display text, need to omit the attribute, not write an empty one. + xAttributes->add(FSNS(XML_w, XML_displayText), rItem.m_aDisplayText); + } + xAttributes->add(FSNS(XML_w, XML_value), rItem.m_aValue); + m_pSerializer->singleElementNS(XML_w, XML_listItem, xAttributes); } m_pSerializer->endElementNS(XML_w, XML_dropDownList); }