sw/qa/extras/ooxmlexport/data/tdf125038_conditionalText3.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx                 |   10 ++++++++++
 writerfilter/source/dmapper/DomainMapper_Impl.cxx             |    7 ++++---
 3 files changed, 14 insertions(+), 3 deletions(-)

New commits:
commit c6cf80af60d23fc52502f88f24dc23ad85462e77
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Thu Jan 19 15:28:14 2023 -0500
Commit:     Justin Luth <jl...@mail.com>
CommitDate: Fri Jan 20 20:22:13 2023 +0000

    related tdf#125038 FORMTEXT/REF: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 FORMTEXT and REF.
    
    With this, all unexpected content is gone from the paragraph.
    
    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.
    
    I also took the opportunity to be able to remove multiple
    spaces from the front of the command.
    
    Change-Id: Ib7e7971bce86bdda545166e398fbb620ca515b91
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145832
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <jl...@mail.com>

diff --git a/sw/qa/extras/ooxmlexport/data/tdf125038_conditionalText3.docx 
b/sw/qa/extras/ooxmlexport/data/tdf125038_conditionalText3.docx
new file mode 100644
index 000000000000..ec5698eeae1c
Binary files /dev/null and 
b/sw/qa/extras/ooxmlexport/data/tdf125038_conditionalText3.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
index 11ddc54f1717..e0c471824193 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
@@ -829,6 +829,16 @@ CPPUNIT_TEST_FIXTURE(Test, testConditionalText2)
     getParagraph(1, "test1");
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testConditionalText3)
+{
+    loadAndReload("tdf125038_conditionalText3.docx");
+    // It is unclear what the purpose of all the conditional IF statements is,
+    // but the end result should not produce any output.
+    // Previously, the fields were being displayed as text
+    // instead of as building blocks for the IF field condition.
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), 
getParagraph(1)->getString().indexOf('2'));
+}
+
 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 0b73640fd57f..b849f453034c 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -264,10 +264,8 @@ static bool IsFieldNestingAllowed(const FieldContextPtr& 
pOuter, const FieldCont
         OUString aCommand = pOuter->GetCommand();
 
         // Ignore leading space before the field name, but don't accept IFF 
when we check for IF.
-        if (!aCommand.isEmpty() && aCommand[0] == ' ')
-        {
+        while (aCommand.getLength() > 3 && aCommand[0] == ' ')
             aCommand = aCommand.subView(1);
-        }
 
         if (aCommand.startsWith("IF "))
         {
@@ -288,10 +286,13 @@ static bool IsFieldNestingAllowed(const FieldContextPtr& 
pOuter, const FieldCont
             switch (*pInner->GetFieldId())
             {
                 case FIELD_DOCVARIABLE:
+                case FIELD_FORMTEXT:
                 case FIELD_FORMULA:
                 case FIELD_IF:
                 case FIELD_MERGEFIELD:
+                case FIELD_REF:
                 {
+                    // LO does not currently know how to evaluate these as 
conditions or results
                     return false;
                 }
                 default:

Reply via email to