summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <michael.stahl@allotropia.de>2021-02-22 16:10:47 +0100
committerMichael Stahl <michael.stahl@allotropia.de>2021-08-23 12:21:05 +0200
commit8417f6b94e55b35179ce636627dfb7f0b2474a6f (patch)
treec240be7f39c30d1c5338cc07f3bb00c476131653
parentbf507f1e0928819e21111165103078b52292c369 (diff)
tdf#140437 ODF import: fix for broken documents with field code as type
Not sure how old the bug that caused this and which filter it was originally but currently the Word import filters don't do that any more. This causes an exception since commit dd24e21bb4f183048a738314934fc3f02ec093f1 so try to fix it up. Change-Id: I087586054ebd5698ed8e8a4054869df202226e92 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111345 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@allotropia.de> (cherry picked from commit d62c93a831080ef332e416dc78f5600c2c5b9850) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111318 Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org> (cherry picked from commit 3a1c4dc5887eee7313fe3f6cb20202df89ac5457)
-rw-r--r--xmloff/source/text/XMLTextMarkImportContext.cxx9
-rw-r--r--xmloff/source/text/txtimp.cxx1
2 files changed, 10 insertions, 0 deletions
diff --git a/xmloff/source/text/XMLTextMarkImportContext.cxx b/xmloff/source/text/XMLTextMarkImportContext.cxx
index 7a919eb99385..8a2e09515d9d 100644
--- a/xmloff/source/text/XMLTextMarkImportContext.cxx
+++ b/xmloff/source/text/XMLTextMarkImportContext.cxx
@@ -200,7 +200,16 @@ static auto InsertFieldmark(SvXMLImport & rImport,
// setup fieldmark...
Reference<text::XFormField> const xFormField(xContent, UNO_QUERY);
assert(xFormField.is());
+ try {
xFormField->setFieldType(fieldmarkTypeName);
+ } catch (uno::RuntimeException const&) {
+ // tdf#140437 somehow old documents had the field code in the type
+ // attribute instead of field:param
+ SAL_INFO("xmloff.text", "invalid fieldmark type, converting to param");
+ // add without checking: FieldParamImporter::Import() catches ElementExistException
+ rHelper.addFieldParam(ODF_CODE_PARAM, fieldmarkTypeName);
+ xFormField->setFieldType(ODF_UNHANDLED);
+ }
rHelper.setCurrentFieldParamsTo(xFormField);
// move cursor after setFieldType as that may delete/re-insert
rHelper.GetCursor()->gotoRange(xContent->getAnchor()->getEnd(), false);
diff --git a/xmloff/source/text/txtimp.cxx b/xmloff/source/text/txtimp.cxx
index ef739d273c6d..e704eb509266 100644
--- a/xmloff/source/text/txtimp.cxx
+++ b/xmloff/source/text/txtimp.cxx
@@ -894,6 +894,7 @@ namespace
}
catch(const ElementExistException&)
{
+ SAL_INFO("xmloff.text", "duplicate fieldmark param");
}
}
}