diff options
author | Michael Stahl <michael.stahl@allotropia.de> | 2022-02-01 13:39:19 +0100 |
---|---|---|
committer | Michael Stahl <michael.stahl@allotropia.de> | 2022-02-02 09:47:23 +0100 |
commit | ea06852ee87531794f07710de496734a647a9062 (patch) | |
tree | 28d27212f238d10fbdca78142d3876ac59e75682 /sw/qa | |
parent | 4d535c4f867d86d40786788e5e5c9fd061a65673 (diff) |
tdf#147008 sw_fieldmarkhide: fix invalid NonTextFieldmark positions
Commit ab6176e88f78d0b3aa2490fbc7858304c2d4a437 introduced a crash
in ModelToViewHelper when the positions of a NonTextFieldmark are invalid.
The NonTextFieldmark must always contain 1 CH_TXT_ATR_FORMELEMENT
but after SplitNode() the position is
(rr) p *pFieldMark->m_pPos1
$2 = SwPosition (node 10, offset 1)
(rr) p *pFieldMark->m_pPos2
$3 = SwPosition (node 9, offset 0)
This is because in ContentIdxStoreImpl::SaveBkmks() there is an
asymmetry where the m_pPos2 is recorded to be wrongly corrected to node
9, but if the positions were swapped so that m_pPos1 is the start
position, then it will not be recorded and remain in node 10.
So fix this by changing the NonTextFieldmark to insert its
CH_TXT_ATR_FORMELEMENT differently.
There is some very subtle code in SwTextNode::Update() that is again
asymmetric and (non-obviously) prefers to move m_pPos2 and leave m_pPos1
alone (by moving it to aTmpIdxReg) in case the positions are equal.
But then the fieldmark code increments "rEnd" (which is really the
m_pPos1 i.e. the start after InsertString() returns), and then
decrements m_pPos2.
So avoid the problem by removing these 2 pointless adjustments.
Then it turns a bunch of tests fail because other code assumes that
m_pPos1 is the end of the NonTextFieldmark, so fix
MarkManager::changeFormFieldmarkType(), ModelToViewHelper and
SwHistoryNoTextFieldmark to use GetMarkStart().
Change-Id: I7c82f9a67661121662c95727e0f8f15e06d85a3a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129289
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Diffstat (limited to 'sw/qa')
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter2.cxx | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx index 5ef95215178b..e0897a6f350f 100644 --- a/sw/qa/extras/uiwriter/uiwriter2.cxx +++ b/sw/qa/extras/uiwriter/uiwriter2.cxx @@ -3589,6 +3589,14 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testCheckboxFormFieldInsertion) pFieldmark = dynamic_cast<::sw::mark::IFieldmark*>(*aIter); CPPUNIT_ASSERT(pFieldmark); CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMCHECKBOX), pFieldmark->GetFieldname()); + + // tdf#147008 this would crash + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + pWrtShell->StartOfSection(false); + pWrtShell->SplitNode(); + CPPUNIT_ASSERT_EQUAL(pFieldmark->GetMarkPos().nNode, pFieldmark->GetOtherMarkPos().nNode); + CPPUNIT_ASSERT_EQUAL(sal_Int32(pFieldmark->GetMarkPos().nContent.GetIndex() + 1), + pFieldmark->GetOtherMarkPos().nContent.GetIndex()); } CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testDropDownFormFieldInsertion) |