[Libreoffice-commits] core.git: sw/source

Ashod Nakashian ashod.nakashian at collabora.co.uk
Fri Nov 10 21:20:46 UTC 2017


 sw/source/core/txtnode/ndtxt.cxx |   26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

New commits:
commit 3b2ae25594774e23ab513ea6f99a0552c7ac5caf
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Fri Nov 10 08:58:29 2017 -0500

    TSCP: strip metadata fields when copying
    
    Since the RDF entries are not copied (due to
    limitations in the clipboard doc), metadata fields
    become inconsistent upon copying. This is especially
    problematic for signatures and classification as
    they are no longer maintainable or verifyable
    (which is a particularly critical issue for crypto
    signatures of paragraphs).
    
    Change-Id: I5468a961ed43befdc48fcea8be00734453917c1f
    Reviewed-on: https://gerrit.libreoffice.org/43631
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index 2fc443a2d4ba..2596f115e9e5 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -1795,14 +1795,16 @@ void SwTextNode::CopyText( SwTextNode *const pDest,
     // Del-Array for all RefMarks without extent
     SwpHts aRefMrkArr;
 
+    std::vector<std::pair<sal_Int32, sal_Int32>> metaFieldRanges;
     sal_Int32 nDeletedDummyChars(0);
     for (size_t n = 0; n < nSize; ++n)
     {
-        const sal_Int32 nAttrStartIdx = m_pSwpHints->Get(n)->GetStart();
+        SwTextAttr * const pHt = m_pSwpHints->Get(n);
+
+        const sal_Int32 nAttrStartIdx = pHt->GetStart();
         if (!( nAttrStartIdx < nEnd))
             break;
 
-        SwTextAttr * const pHt = m_pSwpHints->Get(n);
         const sal_Int32 * const pEndIdx = pHt->GetEnd();
         const sal_uInt16 nWhich = pHt->Which();
 
@@ -1838,6 +1840,13 @@ void SwTextNode::CopyText( SwTextNode *const pDest,
             }
         }
 
+        if (nWhich == RES_TXTATR_METAFIELD)
+        {
+            // Skip metadata fields. Also remember the range to strip the text later.
+            metaFieldRanges.emplace_back(nAttrStartIdx, pEndIdx ? *pEndIdx : nEnd);
+            continue;
+        }
+
         sal_Int32 nAttrStt = 0;
         sal_Int32 nAttrEnd = 0;
 
@@ -1911,6 +1920,19 @@ void SwTextNode::CopyText( SwTextNode *const pDest,
         }
     }
 
+    // Strip the metadata fields, since we don't copy the RDF entries
+    // yet and so they are inconsistent upon copy/pasting.
+    if (!metaFieldRanges.empty())
+    {
+        // Reverse to remove without messing the offsets.
+        std::reverse(metaFieldRanges.begin(), metaFieldRanges.end());
+        for (const auto& pair : metaFieldRanges)
+        {
+            const SwIndex aIdx(pDest, pair.first);
+            pDest->EraseText(aIdx, pair.second - pair.first);
+        }
+    }
+
     // this can only happen when copying into self
     for (SwTextAttr* i : aArr)
     {


More information about the Libreoffice-commits mailing list