sw/qa/filter/ww8/ww8.cxx | 20 ++++++++++++++++++++ sw/source/filter/ww8/docxattributeoutput.cxx | 11 ++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-)
New commits: commit 8af7d4822d525a4b8cea089516755de71c3eca22 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Mon Nov 21 20:05:11 2022 +0100 Commit: Aron Budea <aron.bu...@collabora.com> CommitDate: Thu Jan 26 13:15:43 2023 +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/+/146090 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Aron Budea <aron.bu...@collabora.com> diff --git a/sw/qa/filter/ww8/ww8.cxx b/sw/qa/filter/ww8/ww8.cxx index 7dcb337cd413..3848decc4f46 100644 --- a/sw/qa/filter/ww8/ww8.cxx +++ b/sw/qa/filter/ww8/ww8.cxx @@ -145,6 +145,26 @@ CPPUNIT_TEST_FIXTURE(Test, testDocxSymbolFontExport) assertXPath(pXmlDoc, "//w:p/w:r/w:sym[1]", "font", "Wingdings"); assertXPath(pXmlDoc, "//w:p/w:r/w:sym[1]", "char", "f0e0"); } + +CPPUNIT_TEST_FIXTURE(Test, testDocxContentControlDropdownEmptyDisplayText) +{ + // Given a document with a dropdown content control, the only list item has no display text + // (only a value): + SwDoc* pDoc = createSwDoc(); + 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"); + // 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 e3a7828e5961..0f65ba8cdebe 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -2491,9 +2491,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()) {