sw/source/filter/ww8/ww8atr.cxx | 3 +++ xmloff/source/text/txtfldi.cxx | 3 +++ 2 files changed, 6 insertions(+)
New commits: commit 7471de2849e076304b6e59f4d78b83a272f46607 Author: Skyler Grey <skyler.g...@collabora.com> AuthorDate: Thu Nov 9 16:57:50 2023 +0000 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Fri Nov 10 08:13:11 2023 +0100 Fix STYLEREF crashes and forwards-compatibility This commit fixes a crash in STYLEREF caused by a dereferenced nullptr when serializing chapter fields for .doc export. Along with the STYLEREF changes, I also changed the chapter export logic to allow exporting chapter fields when they were in document text, and to use the style of the thing they pointed to. Unfortunately, in some cases that would be null. This commit makes us fall back to previous behavior in those cases. This commit also adds import logic for styleref on the TEXT namespace in addition to LO_EXT. This is important as if/when the STYLEREF field is no longer LO_EXT we want to be able to open new documents in old versions of libreoffice. This was erroneously missed when we changed TEXT references to LO_EXT in our export logic. Change-Id: I383828c9409afc8545af379307f528cee2e1a960 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159230 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx index 62ae243168ec..6e73e9255495 100644 --- a/sw/source/filter/ww8/ww8atr.cxx +++ b/sw/source/filter/ww8/ww8atr.cxx @@ -3430,6 +3430,9 @@ void AttributeOutputBase::TextField( const SwFormatField& rField ) // Otherwise, get the style of the text and use it as the style name const SwTextNode* pOutlineNd = pTextNd->FindOutlineNodeOfLevel(aCopy.GetLevel()); + if (!pOutlineNd) break; + // Sometimes we can't find the outline node, in that case let's just fallback to exporting the text + sStr = FieldString(ww::eSTYLEREF) + GetExport().GetStyleRefName(pOutlineNd->GetFormatColl()->GetName()); } diff --git a/xmloff/source/text/txtfldi.cxx b/xmloff/source/text/txtfldi.cxx index 4b43240878af..07496cb74c05 100644 --- a/xmloff/source/text/txtfldi.cxx +++ b/xmloff/source/text/txtfldi.cxx @@ -408,6 +408,7 @@ XMLTextFieldImportContext::CreateTextFieldImportContext( case XML_ELEMENT(TEXT, XML_BOOKMARK_REF): case XML_ELEMENT(TEXT, XML_NOTE_REF): case XML_ELEMENT(TEXT, XML_SEQUENCE_REF): + case XML_ELEMENT(TEXT, XML_STYLE_REF): case XML_ELEMENT(LO_EXT, XML_STYLE_REF): pContext = new XMLReferenceFieldImportContext( rImport, rHlp, nToken ); break; @@ -2512,6 +2513,7 @@ void XMLReferenceFieldImportContext::startFastElement( case XML_ELEMENT(TEXT, XML_SEQUENCE_REF): nSource = ReferenceFieldSource::SEQUENCE_FIELD; break; + case XML_ELEMENT(TEXT, XML_STYLE_REF): case XML_ELEMENT(LO_EXT, XML_STYLE_REF): nSource = ReferenceFieldSource::STYLE; break; @@ -2593,6 +2595,7 @@ void XMLReferenceFieldImportContext::PrepareField( { case XML_ELEMENT(TEXT, XML_REFERENCE_REF): case XML_ELEMENT(TEXT, XML_BOOKMARK_REF): + case XML_ELEMENT(TEXT, XML_STYLE_REF): case XML_ELEMENT(LO_EXT, XML_STYLE_REF): xPropertySet->setPropertyValue("SourceName", Any(sName)); xPropertySet->setPropertyValue("ReferenceFieldFlags", Any(nFlags));