summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSkyler Grey <skyler.grey@collabora.com>2023-11-09 16:57:50 +0000
committerMiklos Vajna <vmiklos@collabora.com>2023-11-10 08:12:28 +0100
commit7924d8fc274bb611c829443e0eb1a53d883cc9a3 (patch)
tree9e8b0334114d20c099d5cad3cc37bf3cf64144a7
parent0012f23ca0b59edbb38da055d3388b465146f7eb (diff)
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/+/159226 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
-rw-r--r--sw/source/filter/ww8/ww8atr.cxx3
-rw-r--r--xmloff/source/text/txtfldi.cxx3
2 files changed, 6 insertions, 0 deletions
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index 79446939957e..4949c7ffe6fd 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -3456,6 +3456,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 e0f6a01ecca6..1228e232d328 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));