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 b05a649871446e2ad8419b7c0e9ba7c25370cd07 Author: Xisco Fauli <xiscofa...@libreoffice.org> AuthorDate: Mon Jan 13 10:16:41 2025 +0100 Commit: Christian Lohmaier <lohmaier+libreoff...@googlemail.com> CommitDate: Fri Feb 21 14:23:57 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> (cherry picked from commit ff7bd4d2ac03f39f1da8ead9a6474e84d0f7b277) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181641 Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> Tested-by: Christian Lohmaier <lohmaier+libreoff...@googlemail.com> Reviewed-by: Christian Lohmaier <lohmaier+libreoff...@googlemail.com> 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 96ef31c0cc46..de126574ca78 100644 --- a/sw/qa/extras/uiwriter/uiwriter3.cxx +++ b/sw/qa/extras/uiwriter/uiwriter3.cxx @@ -1189,6 +1189,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 419d0b551c85..bf2d81952dc0 100644 --- a/sw/source/core/fields/reffld.cxx +++ b/sw/source/core/fields/reffld.cxx @@ -1600,6 +1600,9 @@ SwTextNode* SwGetRefFieldType::FindAnchorRefStyleOther(SwDoc* pDoc, SwNodeOffset nReference = pReference->GetIndex(); 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. if (nReference >= nodes.Count() || nodes[nReference] != pReference)