Skip to content

Commit

Permalink
Do not mutate text when reference is not found [MACRO-1718] (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
rithy58 authored Feb 14, 2024
2 parents 4547d7d + 628554b commit 4f16e82
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions libreoffice-core/sw/source/core/fields/reffld.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,6 @@ void SwGetRefField::UpdateField(const SwTextField* pFieldTextAttr, SwFrame* pFra
{
SwDoc& rDoc = static_cast<SwGetRefFieldType*>(GetTyp())->GetDoc();

rText.clear();

// finding the reference target (the number)
sal_Int32 nNumStart = -1;
sal_Int32 nNumEnd = -1;
Expand All @@ -535,11 +533,16 @@ void SwGetRefField::UpdateField(const SwTextField* pFieldTextAttr, SwFrame* pFra
// not found?
if ( !pTextNd )
{
rText = SwViewShell::GetShellRes()->aGetRefField_RefItemNotFound;
// 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;

return;
}

rText.clear();

// where is the category name (e.g. "Illustration")?
const OUString aText = pTextNd->GetText();
const sal_Int32 nCatStart = aText.indexOf(m_sSetRefName);
Expand Down

0 comments on commit 4f16e82

Please sign in to comment.