sw/qa/extras/ooxmlimport/data/__RefNumPara__.docx |binary
 sw/qa/extras/ooxmlimport/ooxmlimport2.cxx         |    7 +++++++
 sw/source/core/unocore/unobkm.cxx                 |   18 +++++++++---------
 3 files changed, 16 insertions(+), 9 deletions(-)

New commits:
commit c19415c20ba0edce2d5f335fba0b788dc5280804
Author:     Mike Kaganski <[email protected]>
AuthorDate: Mon Oct 27 16:08:31 2025 +0500
Commit:     Adolfo Jayme Barrientos <[email protected]>
CommitDate: Fri Oct 31 10:40:00 2025 +0100

    tdf#169090: Only change bookmark type to NUMITEM for paragraph PaMs
    
    In a real-world DOCX, using redlines, there was a bookmark with a name
    starting with "__RefNumPara__", positioned not in the para properties,
    but in the middle of a para text. Opening that DOCX in my debug build
    failed an assertion in ctor of CrossRefBookmark, which requires that
    IDocumentMarkAccess::IsLegalPaMForCrossRefHeadingBookmark returns true.
    
    It makes sense that a NUMITEM bookmark expects a paragraph-wide PaM, so
    just reorder the checks in SwXBookmark::attachToRangeEx. Now it works
    for NUMITEM the same way as for HEADING.
    
    Change-Id: Ia33b54f138d7f61ee72dc3b5c270efdd0fec8068
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193024
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>
    (cherry picked from commit 0b3a4ee85ae264d96bb6dc221dbcf4c394108bff)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193039
    Reviewed-by: Adolfo Jayme Barrientos <[email protected]>

diff --git a/sw/qa/extras/ooxmlimport/data/__RefNumPara__.docx 
b/sw/qa/extras/ooxmlimport/data/__RefNumPara__.docx
new file mode 100644
index 000000000000..b03e08417987
Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/__RefNumPara__.docx 
differ
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx 
b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
index 20735e1e14f1..3fe6676dc57b 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
@@ -1372,6 +1372,13 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf168567)
     }
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testInvalidRefNumPara)
+{
+    // A document with a bookmark which name starts with "__RefNumPara__", 
somewhere in the
+    // middle of a paragraph text. Before the fix, importing it failed an 
assert:
+    createSwDoc("__RefNumPara__.docx");
+}
+
 // tests should only be added to ooxmlIMPORT *if* they fail round-tripping in 
ooxmlEXPORT
 
 } // end of anonymous namespace
diff --git a/sw/source/core/unocore/unobkm.cxx 
b/sw/source/core/unocore/unobkm.cxx
index f66494e164b4..0ddc5cc26e40 100644
--- a/sw/source/core/unocore/unobkm.cxx
+++ b/sw/source/core/unocore/unobkm.cxx
@@ -207,16 +207,16 @@ void SwXBookmark::attachToRangeEx(
     {
          m_pImpl->m_sMarkName = SwMarkName("Bookmark");
     }
-    if ((eType == IDocumentMarkAccess::MarkType::BOOKMARK) &&
-        ::sw::mark::CrossRefNumItemBookmark::IsLegalName(m_pImpl->m_sMarkName))
+    if (eType == IDocumentMarkAccess::MarkType::BOOKMARK)
     {
-        eType = IDocumentMarkAccess::MarkType::CROSSREF_NUMITEM_BOOKMARK;
-    }
-    else if ((eType == IDocumentMarkAccess::MarkType::BOOKMARK) &&
-        ::sw::mark::CrossRefHeadingBookmark::IsLegalName(m_pImpl->m_sMarkName) 
&&
-        IDocumentMarkAccess::IsLegalPaMForCrossRefHeadingBookmark( aPam ) )
-    {
-        eType = IDocumentMarkAccess::MarkType::CROSSREF_HEADING_BOOKMARK;
+        if (IDocumentMarkAccess::IsLegalPaMForCrossRefHeadingBookmark(aPam))
+        {
+            // Both heading and numitem bookmarks require 
IsLegalPaMForCrossRefHeadingBookmark
+            if 
(sw::mark::CrossRefNumItemBookmark::IsLegalName(m_pImpl->m_sMarkName))
+                eType = 
IDocumentMarkAccess::MarkType::CROSSREF_NUMITEM_BOOKMARK;
+            else if 
(sw::mark::CrossRefHeadingBookmark::IsLegalName(m_pImpl->m_sMarkName))
+                eType = 
IDocumentMarkAccess::MarkType::CROSSREF_HEADING_BOOKMARK;
+        }
     }
     m_pImpl->registerInMark(*this,
         m_pImpl->m_pDoc->getIDocumentMarkAccess()->makeMark(

Reply via email to