diff options
-rw-r--r-- | writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx | 9 | ||||
-rw-r--r-- | writerfilter/qa/cppunittests/dmapper/data/field-if-inside-if.docx | bin | 12778 -> 12874 bytes | |||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.cxx | 10 |
3 files changed, 18 insertions, 1 deletions
diff --git a/writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx b/writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx index c7df72b25703..77bd616f37d6 100644 --- a/writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/qa/cppunittests/dmapper/DomainMapper_Impl.cxx @@ -179,6 +179,15 @@ CPPUNIT_TEST_FIXTURE(Test, testFieldIfInsideIf) // - Actual : 0** Expression is faulty **2 // i.e. some of the inner fields escaped outside the outer field. CPPUNIT_ASSERT_EQUAL(OUString("2"), xCell->getString()); + + // Test the second cell: it contains "IF ", not the usual " IF ". + xCell.set(xTable->getCellByName("A2"), uno::UNO_QUERY); + + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 25 + // - Actual : 025 + // i.e. some of the inner fields escaped outside the outer field. + CPPUNIT_ASSERT_EQUAL(OUString("25"), xCell->getString()); } } diff --git a/writerfilter/qa/cppunittests/dmapper/data/field-if-inside-if.docx b/writerfilter/qa/cppunittests/dmapper/data/field-if-inside-if.docx Binary files differindex 93aaab52d497..65e238869b1b 100644 --- a/writerfilter/qa/cppunittests/dmapper/data/field-if-inside-if.docx +++ b/writerfilter/qa/cppunittests/dmapper/data/field-if-inside-if.docx diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index 0a7ae26d937e..d1d0309a6b83 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -206,7 +206,15 @@ static FieldContextPtr GetParentFieldContext(const std::deque<FieldContextPtr>& static bool IsFieldNestingAllowed(const FieldContextPtr& pOuter, const FieldContextPtr& pInner) { std::optional<FieldId> oOuterFieldId = pOuter->GetFieldId(); - if (!oOuterFieldId && pOuter->GetCommand().startsWith(" IF ")) + 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] == ' ') + { + aCommand = aCommand.subView(1); + } + + if (!oOuterFieldId && aCommand.startsWith("IF ")) { // This will be FIELD_IF once the command is closed. oOuterFieldId = FIELD_IF; |