[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.2' - sc/source

Eike Rathke (via logerrit) logerrit at kemper.freedesktop.org
Sun Aug 4 14:52:46 UTC 2019


 sc/source/ui/docshell/externalrefmgr.cxx |   52 ++++++++++++++++++++-----------
 1 file changed, 34 insertions(+), 18 deletions(-)

New commits:
commit 0145a9ef7a2813037dae069d473720cc08854fb7
Author:     Eike Rathke <erack at redhat.com>
AuthorDate: Thu Jul 11 15:50:07 2019 +0200
Commit:     Andras Timar <andras.timar at collabora.com>
CommitDate: Sun Aug 4 16:52:11 2019 +0200

    Postpone loading of all external references, including INDIRECT()
    
    ... which can be constructed with an arbitrary URI text string not
    an svExternal* token type, until link updates are allowed.
    
    Change-Id: I2ce4de415ff99ace04c083c36c1383d76a4ef40d
    Reviewed-on: https://gerrit.libreoffice.org/75422
    Reviewed-by: Eike Rathke <erack at redhat.com>
    Tested-by: Jenkins
    (cherry picked from commit b824b23860b2cf533d4f2428d4a750bd72576181)
    Reviewed-on: https://gerrit.libreoffice.org/75433
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
    (cherry picked from commit 0bdda083c5a7fca62942b3e9bef018d4c8135fe7)
    Reviewed-on: https://gerrit.libreoffice.org/76920
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Andras Timar <andras.timar at collabora.com>

diff --git a/sc/source/ui/docshell/externalrefmgr.cxx b/sc/source/ui/docshell/externalrefmgr.cxx
index e0d0e1dce1ae..14b836327f85 100644
--- a/sc/source/ui/docshell/externalrefmgr.cxx
+++ b/sc/source/ui/docshell/externalrefmgr.cxx
@@ -137,11 +137,12 @@ struct UpdateFormulaCell
 {
     void operator() (ScFormulaCell* pCell) const
     {
-        // Check to make sure the cell really contains ocExternalRef.
+        // Check to make sure the cell really contains svExternal*.
         // External names, external cell and range references all have a
-        // ocExternalRef token.
+        // token of svExternal*. Additionally check for INDIRECT() that can be
+        // called with any constructed URI string.
         ScTokenArray* pCode = pCell->GetCode();
-        if (!pCode->HasExternalRef())
+        if (!pCode->HasExternalRef() && !pCode->HasOpCode(ocIndirect))
             return;
 
         if (pCode->GetCodeError() != FormulaError::NONE)
@@ -1662,6 +1663,17 @@ static std::unique_ptr<ScTokenArray> lcl_fillEmptyMatrix(const ScRange& rRange)
     return pArray;
 }
 
+namespace {
+bool isLinkUpdateAllowedInDoc(const ScDocument& rDoc)
+{
+    SfxObjectShell* pDocShell = rDoc.GetDocumentShell();
+    if (!pDocShell)
+        return false;
+
+    return pDocShell->GetEmbeddedObjectContainer().getUserAllowsLinkUpdate();
+}
+}
+
 ScExternalRefManager::ScExternalRefManager(ScDocument* pDoc) :
     mpDoc(pDoc),
     mbInReferenceMarking(false),
@@ -1951,8 +1963,17 @@ ScExternalRefCache::TokenRef ScExternalRefManager::getSingleRefToken(
     pSrcDoc = getSrcDocument(nFileId);
     if (!pSrcDoc)
     {
-        // Source document not reachable.  Throw a reference error.
-        pToken.reset(new FormulaErrorToken(FormulaError::NoRef));
+        // Source document not reachable.
+        if (!isLinkUpdateAllowedInDoc(*mpDoc))
+        {
+            // Indicate with specific error.
+            pToken.reset(new FormulaErrorToken(FormulaError::LinkFormulaNeedingCheck));
+        }
+        else
+        {
+            // Throw a reference error.
+            pToken.reset(new FormulaErrorToken(FormulaError::NoRef));
+        }
         return pToken;
     }
 
@@ -2159,15 +2180,6 @@ void insertRefCellByIterator(
     }
 }
 
-bool IsLinkUpdateAllowedInDoc(const ScDocument& rDoc)
-{
-    SfxObjectShell* pDocShell = rDoc.GetDocumentShell();
-    if (!pDocShell)
-        return false;
-
-    return pDocShell->GetEmbeddedObjectContainer().getUserAllowsLinkUpdate();
-}
-
 }
 
 void ScExternalRefManager::insertRefCell(sal_uInt16 nFileId, const ScAddress& rCell)
@@ -2378,8 +2390,8 @@ ScDocument* ScExternalRefManager::getInMemorySrcDocument(sal_uInt16 nFileId)
     if (!pFileName)
         return nullptr;
 
-    // Do not load document until it was allowed
-    if (!IsLinkUpdateAllowedInDoc(*mpDoc))
+    // Do not load document until it was allowed.
+    if (!isLinkUpdateAllowedInDoc(*mpDoc))
         return nullptr;
 
     ScDocument* pSrcDoc = nullptr;
@@ -2488,6 +2500,10 @@ SfxObjectShellRef ScExternalRefManager::loadSrcDocument(sal_uInt16 nFileId, OUSt
     if (!isFileLoadable(aFile))
         return nullptr;
 
+    // Do not load document until it was allowed.
+    if (!isLinkUpdateAllowedInDoc(*mpDoc))
+        return nullptr;
+
     OUString aOptions = pFileData->maFilterOptions;
     if ( !pFileData->maFilterName.isEmpty() )
         rFilter = pFileData->maFilterName;      // don't overwrite stored filter with guessed filter
@@ -2626,9 +2642,9 @@ void ScExternalRefManager::maybeLinkExternalFile( sal_uInt16 nFileId, bool bDefe
         aOptions = pFileData->maFilterOptions;
     }
 
-    // Filter detection may access external links; defer it until we are allowed
+    // Filter detection may access external links; defer it until we are allowed.
     if (!bDeferFilterDetection)
-        bDeferFilterDetection = !IsLinkUpdateAllowedInDoc(*mpDoc);
+        bDeferFilterDetection = !isLinkUpdateAllowedInDoc(*mpDoc);
 
     // If a filter was already set (for example, loading the cached table),
     // don't call GetFilterName which has to access the source file.


More information about the Libreoffice-commits mailing list