xmloff/qa/unit/data/comment-table-border.fodt | 16 ++++++++++++++++ xmloff/qa/unit/text.cxx | 8 ++++++++ xmloff/source/text/txtfldi.cxx | 15 +++++++++++++-- 3 files changed, 37 insertions(+), 2 deletions(-)
New commits: commit 132e05b43998ecaaf249b851d690fe7239d79c50 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Mon Aug 30 20:12:46 2021 +0200 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Tue Aug 31 21:02:32 2021 +0200 tdf#126126 ODT import: improve import of cross-table commented text range Regression from commit d4b473dd9ba77427b28d97847067b8877c2033d9 (office:annotation-end import, 2012-07-20), the problem was that XMLAnnotationImportContext::EndElement() assumed that we can always call gotoRange() to go from the annotation start and end points, but this is not true: an annotation may start inside a table and end outside a table, which is not a valid selection, so gotoRange() fails. Fix the regression part by just creating a text range for the anchor of the comment, so the comment is attached to the end of the range, and this way the rest of the comment & the document can be at least opened. [ It seems bookmarks behave similarly: they don't block the whole import, but don't work cross table boundaries, either. ] (cherry picked from commit 4f4452f6a74201e862971a79ba5bdcd06f3ba9ce) Conflicts: xmloff/qa/unit/text.cxx Change-Id: I1b5a2e2e7501ce3054379fc79d2045c3439c52e4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121350 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caol...@redhat.com> diff --git a/xmloff/qa/unit/data/comment-table-border.fodt b/xmloff/qa/unit/data/comment-table-border.fodt new file mode 100644 index 000000000000..29f54da9afe3 --- /dev/null +++ b/xmloff/qa/unit/data/comment-table-border.fodt @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="UTF-8"?> +<office:document xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text"> + <office:body> + <office:text> + <table:table> + <table:table-column table:style-name="Table1.A"/> + <table:table-row> + <table:table-cell table:style-name="Table1.A1" office:value-type="string"> + <text:p>A<office:annotation office:name="0"><text:p>x</text:p></office:annotation>b</text:p> + </table:table-cell> + </table:table-row> + </table:table> + <text:p>b<office:annotation-end office:name="0"/><text:span>Z</text:span></text:p> + </office:text> + </office:body> +</office:document> diff --git a/xmloff/qa/unit/text.cxx b/xmloff/qa/unit/text.cxx index d3b1fcc84a2c..87fde286682d 100644 --- a/xmloff/qa/unit/text.cxx +++ b/xmloff/qa/unit/text.cxx @@ -99,6 +99,14 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testCommentResolved) CPPUNIT_ASSERT(bResolved); } +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testCommentTableBorder) +{ + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "comment-table-border.fodt"; + // Without the accompanying fix in place, this failed to load, as a comment that started in a + // table and ended outside a table aborted the whole importer. + getComponent() = loadFromDesktop(aURL); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/text/txtfldi.cxx b/xmloff/source/text/txtfldi.cxx index 93cd88152a35..a7f606fd36a5 100644 --- a/xmloff/source/text/txtfldi.cxx +++ b/xmloff/source/text/txtfldi.cxx @@ -69,7 +69,7 @@ #include <rtl/math.hxx> #include <tools/debug.hxx> #include <osl/diagnose.h> - +#include <tools/diagnose_ex.h> using namespace ::com::sun::star; using namespace ::com::sun::star::uno; @@ -3253,7 +3253,18 @@ void XMLAnnotationImportContext::endFastElement(sal_Int32 /*nElement*/) uno::Reference<text::XText> xText = GetImportHelper().GetText(); uno::Reference<text::XTextCursor> xCursor = xText->createTextCursorByRange(GetImportHelper().GetCursorAsRange()); - xCursor->gotoRange(xPrevField->getAnchor(), true); + try + { + xCursor->gotoRange(xPrevField->getAnchor(), true); + } + catch (const uno::RuntimeException&) + { + // Loosing the start of the anchor is better than not opening the document at + // all. + TOOLS_WARN_EXCEPTION( + "xmloff.text", + "XMLAnnotationImportContext::endFastElement: gotoRange() failed: "); + } xText->insertTextContent(xCursor, xPrevField, !xCursor->isCollapsed()); }