sw/qa/extras/ooxmlexport/data/tdf125038_conditionalText_DOCPROPERTY.docx |binary sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx | 6 ++++++ sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx | 9 +++++++-- 3 files changed, 13 insertions(+), 2 deletions(-)
New commits: commit 0fb23379e63071ec155cb6683c19212859e399b5 Author: Justin Luth <justin.l...@collabora.com> AuthorDate: Tue Oct 8 12:01:59 2024 -0400 Commit: Justin Luth <jl...@mail.com> CommitDate: Tue Oct 8 20:50:11 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> 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 ad6b1a9d35d4..be712f80290f 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx @@ -913,6 +913,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/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx index 5c0974007e37..85b8109c4920 100644 --- a/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx +++ b/sw/source/writerfilter/dmapper/DomainMapper_Impl.cxx @@ -316,6 +316,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: @@ -329,6 +330,7 @@ static bool IsFieldNestingAllowed(const FieldContextPtr& pOuter, const FieldCont return false; } default: + // TODO: tdf#125038 suggests everything probably needs to return false break; } break; @@ -7918,8 +7920,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 : {