sw/qa/extras/htmlexport/data/tdf160390.fodt | 17 ++++++++++ sw/qa/extras/htmlexport/htmlexport.cxx | 7 ++++ sw/source/filter/html/htmlatr.cxx | 44 +++++++++++++--------------- 3 files changed, 45 insertions(+), 23 deletions(-)
New commits: commit c0f3dc4875f0b40110f1d3513828d2ebf8a4b8aa Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Wed Mar 27 16:01:51 2024 +0500 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Thu Mar 28 11:37:19 2024 +0500 tdf#160390: make sure to forward the iterator Change-Id: I302cc4303f083a1024175ce4ba00ce8021c6d4c9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165390 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/sw/qa/extras/htmlexport/data/tdf160390.fodt b/sw/qa/extras/htmlexport/data/tdf160390.fodt new file mode 100644 index 000000000000..53d6144ff19b --- /dev/null +++ b/sw/qa/extras/htmlexport/data/tdf160390.fodt @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text"> + <office:automatic-styles> + <style:style style:name="P1" style:family="paragraph"> + <style:text-properties style:text-underline-style="solid" fo:font-weight="bold"/> + </style:style> + <style:style style:name="T1" style:family="text"> + <style:text-properties style:text-underline-style="none" fo:font-weight="normal"/> + </style:style> + </office:automatic-styles> + <office:body> + <office:text> + <text:p text:style-name="P1">foo<text:span text:style-name="T1"> </text:span></text:p> + </office:text> + </office:body> +</office:document> \ No newline at end of file diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index 4afef3cccc96..7c8bf0985ff8 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -3047,6 +3047,13 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testHTML_Tdf160017_spanClosingOrder) CPPUNIT_ASSERT(parseXml(maTempFile)); } +CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testHTML_Tdf160390) +{ + // This document must not hang infinitely on HTML export + createSwDoc("tdf160390.fodt"); + save("HTML (StarWriter)"); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/html/htmlatr.cxx b/sw/source/filter/html/htmlatr.cxx index 247b22e5ff2f..0731c3709571 100644 --- a/sw/source/filter/html/htmlatr.cxx +++ b/sw/source/filter/html/htmlatr.cxx @@ -1526,8 +1526,9 @@ void HTMLEndPosLst::SplitItem( const SfxPoolItem& rItem, sal_Int32 nStart, for (auto it = items.begin(); it != items.end();) { - HTMLStartEndPos* pTest = *it; - sal_Int32 nTestEnd = pTest->GetEnd(); + auto itTest = it++; // forward early, allow 'continue', and keep a copy for 'erase' + HTMLStartEndPos* pTest = *itTest; + const sal_Int32 nTestEnd = pTest->GetEnd(); if (nTestEnd <= nStart) continue; @@ -1535,30 +1536,27 @@ void HTMLEndPosLst::SplitItem( const SfxPoolItem& rItem, sal_Int32 nStart, const SfxPoolItem& rTestItem = pTest->GetItem(); // only the corresponding OnTag attributes have to be considered - if (rTestItem.Which() == nWhich && HTML_ON_VALUE == GetHTMLItemState(rTestItem)) - { - // if necessary, insert the second part of the split - // attribute - if (nTestEnd > nEnd) - InsertItem(pTest->GetItem(), nEnd, nTestEnd); + if (rTestItem.Which() != nWhich || HTML_ON_VALUE != GetHTMLItemState(rTestItem)) + continue; - if (nTestStart >= nStart) - { - // the Test item only starts after the new end of the - // attribute. Therefore, it can be completely erased. - it = items.erase(it); - auto& posItems = m_aEndLst[pTest->GetEnd()]; - posItems.erase(std::remove(posItems.begin(), posItems.end(), pTest), - posItems.end()); - delete pTest; - continue; - } + // if necessary, insert the second part of the split attribute + if (nTestEnd > nEnd) + InsertItem(rTestItem, nEnd, nTestEnd); - // the start of the new attribute corresponds to the new - // end of the attribute - FixSplittedItem(pTest, nStart); + if (nTestStart >= nStart) + { + // the Test item only starts after the new end of the + // attribute. Therefore, it can be completely erased. + it = items.erase(itTest); + auto& posItems = m_aEndLst[nTestEnd]; + posItems.erase(std::remove(posItems.begin(), posItems.end(), pTest), + posItems.end()); + delete pTest; + continue; } - ++it; + + // the start of the new attribute corresponds to the new end of the attribute + FixSplittedItem(pTest, nStart); } } }