sw/qa/extras/htmlexport/htmlexport.cxx |    5 ++---
 sw/source/filter/html/wrthtml.cxx      |    8 ++++++++
 2 files changed, 10 insertions(+), 3 deletions(-)

New commits:
commit b9d4e9c3c10f0d76ecf83dbd259ba6e5544836e9
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Tue Jul 26 13:47:54 2022 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Wed Jul 27 13:41:24 2022 +0200

    sw reqif-xhtml export: fix duplicated bookmark names in fragments
    
    The problem was that exporting multiple documents to reqif fragments and
    then combining them to a single document resulted in non-unique bookmark
    identifiers, even if they were unique in the original source documents.
    
    Writer already tries to ensure unique bookmark names, but if the export
    result is not a full document on its own, this is not enough. On the
    other hand, bookmarks in these fragments are almost always used
    unintentionally.
    
    Fix the problem by keeping the bookmark output in the HTML/XHTML case,
    but disable it for ReqIF.
    
    Note that we disable unique anchors in general, so this fixes the same
    problem with section anchors as well.
    
    (cherry picked from commit 4e6327c673075ab4a44f497a06a8dbf759c1a72a)
    
    Change-Id: Ib47d1589fa08d205b7904e21656c937bfbca0a2f

diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index 851d8409b549..9d2aed175a66 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -620,9 +620,8 @@ DECLARE_HTMLEXPORT_TEST(testReqIfParagraph, "reqif-p.xhtml")
     // This was "<font>" instead of CSS + namespace prefix was missing.
     CPPUNIT_ASSERT(aStream.indexOf("<reqif-xhtml:span style=\"color: 
#ce181e\"") != -1);
 
-    // This was '<a name="Bookmark 1"': missing namespace prefix, wrong
-    // attribute name, wrong attribute value.
-    CPPUNIT_ASSERT(aStream.indexOf("<reqif-xhtml:a 
id=\"Bookmark_1\"></reqif-xhtml:a>") != -1);
+    // This was '<reqif-xhtml:a id="...">': non-unique bookmark name in reqif 
fragment.
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-1), 
aStream.indexOf("<reqif-xhtml:a id="));
 }
 
 DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testReqIfOleData, "reqif-ole-data.xhtml")
diff --git a/sw/source/filter/html/wrthtml.cxx 
b/sw/source/filter/html/wrthtml.cxx
index 8aeaf9c32fac..aa604cfa24b4 100644
--- a/sw/source/filter/html/wrthtml.cxx
+++ b/sw/source/filter/html/wrthtml.cxx
@@ -1206,6 +1206,14 @@ const SwPageDesc *SwHTMLWriter::MakeHeader( sal_uInt16 
&rHeaderAttrs )
 
 void SwHTMLWriter::OutAnchor( const OUString& rName )
 {
+    if (mbReqIF)
+    {
+        // <a id=".."> has to be unique inside the whole document, but
+        // we only write a fragment, so we can't ensure the ID is indeed
+        // unique. Just don't write anchors in the ReqIF case.
+        return;
+    }
+
     OStringBuffer sOut;
     sOut.append("<" + GetNamespace() + OOO_STRING_SVTOOLS_HTML_anchor " ");
     if (!mbXHTML)

Reply via email to