sw/qa/extras/ooxmlexport/data/tdf125038_conditionalText_DOCPROPERTY.docx |binary sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx | 6 ++++++ writerfilter/source/dmapper/DomainMapper_Impl.cxx | 9 +++++++-- 3 files changed, 13 insertions(+), 2 deletions(-)
New commits: commit fbf819d456461aa35083110eaf81b4f90c412bb8 Author: Justin Luth <justin.l...@collabora.com> AuthorDate: Tue Oct 8 12:01:59 2024 -0400 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Wed Oct 9 22:09:06 2024 +0200 related tdf#125038 DOCPROPERTY:fix spurious text outside IF field This builds on top of commit d09336fbdceaafd9320466b660a2b32a07dcc16a (tdf#125038 DOCX import: fix lost MERGEFIELD result inside an IF field, 2019-10-31), and extends it for DOCPROPERTY. With this, all unexpected content is gone from the paragraph. [In a previous related commit, I wrote: Actually this is all somewhat irrelevant since DOCX doesn't import IF fields at all anyway - they are just left blank. So AFAICS, we should ALWAYS return false at this point.] make CppunitTest_sw_ooxmlfieldexport \ CPPUNIT_TEST_NAME=testConditionalText4 Not surprisingly, there were no existing unit tests that matched (because I already did a crash-testing assert last year). Change-Id: I4d737172ee278c07596eaf47e1bc320e4f42be55 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174699 Tested-by: Jenkins Reviewed-by: Justin Luth <jl...@mail.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174710 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/qa/extras/ooxmlexport/data/tdf125038_conditionalText_DOCPROPERTY.docx b/sw/qa/extras/ooxmlexport/data/tdf125038_conditionalText_DOCPROPERTY.docx new file mode 100644 index 000000000000..9c47605c8275 Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf125038_conditionalText_DOCPROPERTY.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx index 66faba5f3e59..0e3c46a9dedb 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx @@ -852,6 +852,12 @@ CPPUNIT_TEST_FIXTURE(Test, testConditionalText3) CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), getParagraph(1)->getString().indexOf('2')); } +CPPUNIT_TEST_FIXTURE(Test, testConditionalText4) +{ + loadAndReload("tdf125038_conditionalText_DOCPROPERTY.docx"); + getParagraph(1, u"customized field"_ustr); +} + DECLARE_OOXMLEXPORT_TEST(testTdf142464_ampm, "tdf142464_ampm.docx") { css::uno::Reference<css::text::XTextFieldsSupplier> xTextFieldsSupplier( diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index 0087d5263e25..99eb372dce20 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -300,6 +300,7 @@ static bool IsFieldNestingAllowed(const FieldContextPtr& pOuter, const FieldCont switch (*pInner->GetFieldId()) { case FIELD_DOCVARIABLE: + case FIELD_DOCPROPERTY: case FIELD_FORMTEXT: case FIELD_FORMULA: case FIELD_IF: @@ -312,6 +313,7 @@ static bool IsFieldNestingAllowed(const FieldContextPtr& pOuter, const FieldCont return false; } default: + // TODO: tdf#125038 suggests everything probably needs to return false break; } break; @@ -7737,8 +7739,11 @@ void DomainMapper_Impl::CloseFieldCommand() } break; case FIELD_DOCPROPERTY : - handleDocProperty(pContext, sFirstParam, - xFieldInterface); + { + FieldContextPtr pOuter = GetParentFieldContext(m_aFieldStack); + if (!pOuter || IsFieldNestingAllowed(pOuter, m_aFieldStack.back())) + handleDocProperty(pContext, sFirstParam, xFieldInterface); + } break; case FIELD_DOCVARIABLE : {