sw/source/filter/ww8/docxattributeoutput.cxx |   12 ++++++++++--
 sw/source/filter/ww8/docxattributeoutput.hxx |    7 +++++--
 2 files changed, 15 insertions(+), 4 deletions(-)

New commits:
commit 08111edaeb425f1b66d0c69c415dbd7d2f44ac8c
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Mon Jan 6 12:07:46 2025 +0000
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Mon Jan 6 15:22:31 2025 +0100

    crashtesting: assert on reimport of forum-mso-en-2419.docx
    
    after export to docx. Use similar duplicate preventation mechanism as
    normal bookmarks and annotations use.
    
    Change-Id: I31a70f1ee437a5d8cce790c7ec2c7a8d5894d3f7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/179828
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Tested-by: Jenkins

diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index 0cd8b728bbb3..5fc619f3ecb2 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -2336,8 +2336,12 @@ void 
DocxAttributeOutput::DoWriteBookmarksEnd(std::vector<OUString>& rEnds)
 // - "permission-for-user:<permission-id>:<permission-user-name>"
 // - "permission-for-group:<permission-id>:<permission-group-name>"
 //
-void DocxAttributeOutput::DoWritePermissionTagStart(std::u16string_view 
permission)
+void DocxAttributeOutput::DoWritePermissionTagStart(const OUString& permission)
 {
+    if (m_aOpenedPermissions.find(permission) != m_aOpenedPermissions.end())
+        return;
+    m_aOpenedPermissions.insert(permission);
+
     std::u16string_view permissionIdAndName;
 
     sal_Int32 nFSNS;
@@ -2371,8 +2375,11 @@ void 
DocxAttributeOutput::DoWritePermissionTagStart(std::u16string_view permissi
 // - "permission-for-user:<permission-id>:<permission-user-name>"
 // - "permission-for-group:<permission-id>:<permission-group-name>"
 //
-void DocxAttributeOutput::DoWritePermissionTagEnd(std::u16string_view 
permission)
+void DocxAttributeOutput::DoWritePermissionTagEnd(const OUString& permission)
 {
+    if (m_aOpenedPermissions.find(permission) == m_aOpenedPermissions.end())
+        return;
+
     std::u16string_view permissionIdAndName;
 
     auto const ok = o3tl::starts_with(permission, u"permission-for-group:", 
&permissionIdAndName) ||
@@ -2385,6 +2392,7 @@ void 
DocxAttributeOutput::DoWritePermissionTagEnd(std::u16string_view permission
 
     m_pSerializer->singleElementNS(XML_w, XML_permEnd,
         FSNS(XML_w, XML_id), GetExport().BookmarkToWord(permissionId));
+    m_aOpenedPermissions.erase(permission);
 }
 
 /// Write the start permissions
diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx 
b/sw/source/filter/ww8/docxattributeoutput.hxx
index 385ce344c21d..e19940a673a2 100644
--- a/sw/source/filter/ww8/docxattributeoutput.hxx
+++ b/sw/source/filter/ww8/docxattributeoutput.hxx
@@ -783,8 +783,8 @@ private:
     void DoWriteBookmarkStartIfExist(sal_Int32 nRunPos);
     void DoWriteBookmarkEndIfExist(sal_Int32 nRunPos);
 
-    void DoWritePermissionTagStart(std::u16string_view permission);
-    void DoWritePermissionTagEnd(std::u16string_view permission);
+    void DoWritePermissionTagStart(const OUString& permission);
+    void DoWritePermissionTagEnd(const OUString& permission);
     void DoWritePermissionsStart();
     void DoWritePermissionsEnd();
 
@@ -927,6 +927,9 @@ private:
     /// Name of the last opened annotation mark.
     OUString m_sLastOpenedAnnotationMark;
 
+    /// Set of currently opened permissions
+    std::unordered_set<OUString> m_aOpenedPermissions;
+
     /// If there are bookmarks around sequence fields, this map contains the
     /// names of these bookmarks for each sequence.
     std::map<OUString, std::vector<OUString> > m_aSeqBookmarksNames;

Reply via email to