sw/qa/extras/uiwriter/data/tdf164620.docx |binary sw/qa/extras/uiwriter/uiwriter3.cxx | 18 ++++++++++++++++++ sw/source/core/fields/reffld.cxx | 3 +++ 3 files changed, 21 insertions(+)
New commits: commit ff7bd4d2ac03f39f1da8ead9a6474e84d0f7b277 Author: Xisco Fauli <xiscofa...@libreoffice.org> AuthorDate: Mon Jan 13 10:16:41 2025 +0100 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Thu Feb 13 17:46:06 2025 +0100 tdf#164620: sw_uiwriter3: Add unittest and fix another edge case it found. Change-Id: Ia57ae1c9a13279f240b78f90fd05faa2f0da7ce5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180162 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/qa/extras/uiwriter/data/tdf164620.docx b/sw/qa/extras/uiwriter/data/tdf164620.docx new file mode 100644 index 000000000000..6e74b6bf7fe3 Binary files /dev/null and b/sw/qa/extras/uiwriter/data/tdf164620.docx differ diff --git a/sw/qa/extras/uiwriter/uiwriter3.cxx b/sw/qa/extras/uiwriter/uiwriter3.cxx index 9be08e248dfc..2d2ad13e20bb 100644 --- a/sw/qa/extras/uiwriter/uiwriter3.cxx +++ b/sw/qa/extras/uiwriter/uiwriter3.cxx @@ -1222,6 +1222,24 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf100691) CPPUNIT_ASSERT_EQUAL(u"Text 1"_ustr, pNext->GetText()); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf164620) +{ + createSwDoc("tdf164620.docx"); + + CPPUNIT_ASSERT_EQUAL(2, getPages()); + + dispatchCommand(mxComponent, u".uno:SelectAll"_ustr, {}); + + // Without the fix in place, this test would have crashed here + dispatchCommand(mxComponent, u".uno:Delete"_ustr, {}); + + CPPUNIT_ASSERT_EQUAL(1, getPages()); + + dispatchCommand(mxComponent, u".uno:Undo"_ustr, {}); + + CPPUNIT_ASSERT_EQUAL(2, getPages()); +} + CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf134404) { createSwDoc("tdf134404.odt"); diff --git a/sw/source/core/fields/reffld.cxx b/sw/source/core/fields/reffld.cxx index 35480504f17f..6499260aefd3 100644 --- a/sw/source/core/fields/reffld.cxx +++ b/sw/source/core/fields/reffld.cxx @@ -1637,6 +1637,9 @@ SwTextNode* SwGetRefFieldType::FindAnchorRefStyleOther(SwDoc* pDoc, const SwNodes& nodes = pDoc->GetNodes(); + if (&nodes != &pReference->GetNodes()) + return nullptr; + // It is possible to end up here, with a pReference pointer which points to a node which has already been // removed from the nodes array, which means that calling GetIndex() returns an incorrect index. SwNodeOffset nReference;