sw/inc/swtypes.hxx | 1 + sw/qa/uibase/fldui/fldui.cxx | 26 ++++++++++++++++++++++++++ sw/source/core/fields/docufld.cxx | 10 +++++----- sw/source/filter/ww8/ww8atr.cxx | 2 +- sw/source/ui/fldui/fldfunc.cxx | 9 ++++++--- 5 files changed, 39 insertions(+), 9 deletions(-)
New commits: commit a338ec1d3b2293ff34b159bb2a2da67e249d5655 Author: Andreas Heinisch <[email protected]> AuthorDate: Fri Feb 6 08:36:36 2026 +0100 Commit: Andreas Heinisch <[email protected]> CommitDate: Sun Feb 8 19:29:20 2026 +0100 tdf#56126 - Changed separator for conditional fields In order to support the previosuly used vertical separator. Change-Id: I62d05a1ce9e95d34879ac2970c57fd0e4f78f987 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/198813 Tested-by: Jenkins Reviewed-by: Andreas Heinisch <[email protected]> diff --git a/sw/inc/swtypes.hxx b/sw/inc/swtypes.hxx index a6e54c491e9c..a111cec61540 100644 --- a/sw/inc/swtypes.hxx +++ b/sw/inc/swtypes.hxx @@ -129,6 +129,7 @@ const char cSequenceMarkSeparator = '!'; sal_Unicode const toxMarkSeparator = '\u0019'; #define DB_DELIM u'\x00ff' // Database <-> table separator. +#define CONDITIONAL_FIELD_SEPARATOR u' enum class SetAttrMode { diff --git a/sw/qa/uibase/fldui/fldui.cxx b/sw/qa/uibase/fldui/fldui.cxx index 7290dbff605a..ea1168e89a36 100644 --- a/sw/qa/uibase/fldui/fldui.cxx +++ b/sw/qa/uibase/fldui/fldui.cxx @@ -119,6 +119,32 @@ CPPUNIT_TEST_FIXTURE(Test, testInsertRefmark) CPPUNIT_ASSERT_EQUAL(u"aaabbbccc"_ustr, pTextNode->GetText()); } +CPPUNIT_TEST_FIXTURE(Test, testTdf56126InsertConditionalFieldWithVerticalSeparator) +{ + // Create an empty document + createSwDoc(); + SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell(); + + // Insert a conditional field containing exactly two dots for its condition + SwFieldMgr aFieldMgr(pWrtShell); + SwInsertField_Data aFieldData(SwFieldTypesEnum::ConditionalText, 0, u"true"_ustr, + u"foo|bar"_ustr, 0); + CPPUNIT_ASSERT(aFieldMgr.InsertField(aFieldData)); + pWrtShell->SttEndDoc(true); + + // Without the accompanying fix in place, this test would have failed with: + // - Expected: foo|bar + // - Actual : foo + // i.e. the conditional text after the vertical separator disappeared + CPPUNIT_ASSERT_EQUAL(u"foo|bar"_ustr, pWrtShell->GetCurField()->ExpandField(true, nullptr)); + + // Reload document in order to check if the new separator will be saved in ODT + saveAndReload(TestFilter::ODT); + pWrtShell = getSwDocShell()->GetWrtShell(); + pWrtShell->SttEndDoc(true); + CPPUNIT_ASSERT_EQUAL(u"foo|bar"_ustr, pWrtShell->GetCurField()->ExpandField(true, nullptr)); +} + CPPUNIT_TEST_FIXTURE(Test, testTdf68364InsertConditionalFieldWithTwoDots) { // Create an empty document diff --git a/sw/source/core/fields/docufld.cxx b/sw/source/core/fields/docufld.cxx index 7934cbf2795f..f3ee1a7acff4 100644 --- a/sw/source/core/fields/docufld.cxx +++ b/sw/source/core/fields/docufld.cxx @@ -1352,14 +1352,14 @@ SwHiddenTextField::SwHiddenTextField( SwHiddenTextFieldType* pFieldType, if(m_nSubType == SwFieldTypesEnum::ConditionalText) { sal_Int32 nPos = 0; - m_aTRUEText = rStr.getToken(0, '|', nPos); + m_aTRUEText = rStr.getToken(0, CONDITIONAL_FIELD_SEPARATOR, nPos); if(nPos != -1) { - m_aFALSEText = rStr.getToken(0, '|', nPos); + m_aFALSEText = rStr.getToken(0, CONDITIONAL_FIELD_SEPARATOR, nPos); if(nPos != -1) { - m_aContent = rStr.getToken(0, '|', nPos); + m_aContent = rStr.getToken(0, CONDITIONAL_FIELD_SEPARATOR, nPos); m_bValid = true; } } @@ -1493,7 +1493,7 @@ void SwHiddenTextField::SetPar2(const OUString& rStr) { if (m_nSubType == SwFieldTypesEnum::ConditionalText) { - sal_Int32 nPos = rStr.indexOf('|'); + sal_Int32 nPos = rStr.indexOf(CONDITIONAL_FIELD_SEPARATOR); if (nPos == -1) m_aTRUEText = rStr; else @@ -1513,7 +1513,7 @@ OUString SwHiddenTextField::GetPar2() const { return m_aTRUEText; } - return m_aTRUEText + "|" + m_aFALSEText; + return OUString::Concat(m_aTRUEText) + OUStringChar(CONDITIONAL_FIELD_SEPARATOR) + m_aFALSEText; } SwFieldTypesEnum SwHiddenTextField::GetSubType() const diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx index e2b1749abe9a..20bd53cb94fd 100644 --- a/sw/source/filter/ww8/ww8atr.cxx +++ b/sw/source/filter/ww8/ww8atr.cxx @@ -3501,7 +3501,7 @@ void AttributeOutputBase::TextField( const SwFormatField& rField ) { OUString aCond = pField->GetPar1(); OUString aTrueFalse = pField->GetPar2(); - sal_Int32 nPos = aTrueFalse.indexOf('|'); + sal_Int32 nPos = aTrueFalse.indexOf(CONDITIONAL_FIELD_SEPARATOR); OUString aTrue; OUString aFalse; if (nPos == -1) diff --git a/sw/source/ui/fldui/fldfunc.cxx b/sw/source/ui/fldui/fldfunc.cxx index fca88f9ca8e2..ebdc780e8966 100644 --- a/sw/source/ui/fldui/fldfunc.cxx +++ b/sw/source/ui/fldui/fldfunc.cxx @@ -334,8 +334,10 @@ IMPL_LINK_NOARG(SwFieldFuncPage, TypeHdl, weld::TreeView&, void) if (IsFieldEdit()) { sal_Int32 nIdx{ 0 }; - m_xCond1ED->set_text(GetCurField()->GetPar2().getToken(0, '|', nIdx)); - m_xCond2ED->set_text(GetCurField()->GetPar2().getToken(0, '|', nIdx)); + m_xCond1ED->set_text( + GetCurField()->GetPar2().getToken(0, CONDITIONAL_FIELD_SEPARATOR, nIdx)); + m_xCond2ED->set_text( + GetCurField()->GetPar2().getToken(0, CONDITIONAL_FIELD_SEPARATOR, nIdx)); } bName = bValue = true; @@ -548,7 +550,8 @@ bool SwFieldFuncPage::FillItemSet(SfxItemSet* ) break; case SwFieldTypesEnum::ConditionalText: - aVal = m_xCond1ED->get_text() + "|" + m_xCond2ED->get_text(); + aVal = OUString::Concat(m_xCond1ED->get_text()) + + OUStringChar(CONDITIONAL_FIELD_SEPARATOR) + m_xCond2ED->get_text(); break; case SwFieldTypesEnum::Dropdown : {
