sw/qa/extras/htmlexport/data/tdf160390.fodt |   17 +++++++++++
 sw/qa/extras/htmlexport/htmlexport.cxx      |    7 ++++
 sw/source/filter/html/htmlatr.cxx           |   40 +++++++++++++---------------
 3 files changed, 43 insertions(+), 21 deletions(-)

New commits:
commit d9c778391796e91ea3da361bf3901000350c26dd
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Wed Mar 27 16:01:51 2024 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Wed Mar 27 17:06:38 2024 +0100

    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 374c739230e5..6a23599184a5 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -3075,6 +3075,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");
+    ExportToHTML();
+}
+
 } // end of anonymous namespace
 CPPUNIT_PLUGIN_IMPLEMENT();
 
diff --git a/sw/source/filter/html/htmlatr.cxx 
b/sw/source/filter/html/htmlatr.cxx
index c880082018f1..f298f93dc5b2 100644
--- a/sw/source/filter/html/htmlatr.cxx
+++ b/sw/source/filter/html/htmlatr.cxx
@@ -1524,8 +1524,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;
 
@@ -1533,28 +1534,25 @@ 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);
-                    std::erase(m_aEndLst[pTest->GetEnd()], pTest);
-                    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);
+                std::erase(m_aEndLst[nTestEnd], pTest);
+                delete pTest;
+                continue;
             }
-            ++it;
+
+            // the start of the new attribute corresponds to the new end of 
the attribute
+            FixSplittedItem(pTest, nStart);
         }
     }
 }

Reply via email to