sw/qa/filter/ww8/ww8.cxx | 20 ++++++++++++++++++++ sw/source/filter/ww8/docxattributeoutput.cxx | 11 ++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-)
New commits: commit 017c38a9702da0566ac1ce5d758444e5ff25df9d Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Mon Nov 21 20:05:11 2022 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Tue Nov 22 08:05:18 2022 +0100 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> diff --git a/sw/qa/filter/ww8/ww8.cxx b/sw/qa/filter/ww8/ww8.cxx index 1057939d993d..0810a15a54c3 100644 --- a/sw/qa/filter/ww8/ww8.cxx +++ b/sw/qa/filter/ww8/ww8.cxx @@ -139,6 +139,26 @@ CPPUNIT_TEST_FIXTURE(Test, testDocxHyperlinkShape) // assertion failure for not-well-formed XML output): save("Office Open XML Text"); } + +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"); + SwDoc* pDoc = getSwDoc(); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->InsertContentControl(SwContentControlType::DROP_DOWN_LIST); + + // When saving to DOCX: + save("Office Open XML Text"); + + // Then make sure that no display text attribute is written: + xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml"); + // 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 4a0e4325d580..26ed9d57a95b 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -2415,9 +2415,14 @@ void DocxAttributeOutput::WriteContentControlStart() } 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); } if (m_pContentControl->GetComboBox()) {