From 0433e1aa21562aa8e7203e0c1185d8395e690cd2 Mon Sep 17 00:00:00 2001 From: Rithy Muth Date: Mon, 12 Feb 2024 14:39:31 -0500 Subject: [PATCH 1/2] Do not mutate text when reference is not found --- libreoffice-core/sw/source/core/fields/reffld.cxx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libreoffice-core/sw/source/core/fields/reffld.cxx b/libreoffice-core/sw/source/core/fields/reffld.cxx index 1f8aae4e35..f96d052042 100644 --- a/libreoffice-core/sw/source/core/fields/reffld.cxx +++ b/libreoffice-core/sw/source/core/fields/reffld.cxx @@ -523,8 +523,6 @@ void SwGetRefField::UpdateField(const SwTextField* pFieldTextAttr, SwFrame* pFra { SwDoc& rDoc = static_cast(GetTyp())->GetDoc(); - rText.clear(); - // finding the reference target (the number) sal_Int32 nNumStart = -1; sal_Int32 nNumEnd = -1; @@ -535,11 +533,15 @@ void SwGetRefField::UpdateField(const SwTextField* pFieldTextAttr, SwFrame* pFra // not found? if ( !pTextNd ) { - rText = SwViewShell::GetShellRes()->aGetRefField_RefItemNotFound; + // LibreOffice would update the referenced text to "Error: Reference source not found" + // when the source is, well, not found, e.g source got deleted + // rText = SwViewShell::GetShellRes()->aGetRefField_RefItemNotFound; return; } + rText.clear(); + // where is the category name (e.g. "Illustration")? const OUString aText = pTextNd->GetText(); const sal_Int32 nCatStart = aText.indexOf(m_sSetRefName); From 628554b0ee324bf24d70ee1ac8dd5038e13b31ab Mon Sep 17 00:00:00 2001 From: Rithy Muth Date: Mon, 12 Feb 2024 15:24:20 -0500 Subject: [PATCH 2/2] Add link to ticket --- libreoffice-core/sw/source/core/fields/reffld.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/libreoffice-core/sw/source/core/fields/reffld.cxx b/libreoffice-core/sw/source/core/fields/reffld.cxx index f96d052042..63656bafc8 100644 --- a/libreoffice-core/sw/source/core/fields/reffld.cxx +++ b/libreoffice-core/sw/source/core/fields/reffld.cxx @@ -533,6 +533,7 @@ void SwGetRefField::UpdateField(const SwTextField* pFieldTextAttr, SwFrame* pFra // not found? if ( !pTextNd ) { + // https://www.notion.so/macrocom/NoReferenceError-in-Document-text-for-invalid-references-03bf8156aec3427a8b974d2545e63041 // LibreOffice would update the referenced text to "Error: Reference source not found" // when the source is, well, not found, e.g source got deleted // rText = SwViewShell::GetShellRes()->aGetRefField_RefItemNotFound;