[Libreoffice-commits] core.git: 7 commits - sc/inc sc/source

Eike Rathke erack at redhat.com
Tue Feb 13 17:46:33 UTC 2018


 sc/inc/stringutil.hxx                  |    7 +++++++
 sc/source/core/data/column3.cxx        |   10 +++++++---
 sc/source/core/data/documentimport.cxx |    9 ++++++++-
 sc/source/core/tool/stringutil.cxx     |    3 ++-
 sc/source/filter/rtf/eeimpars.cxx      |    1 +
 sc/source/ui/docshell/impex.cxx        |   17 +++++------------
 6 files changed, 30 insertions(+), 17 deletions(-)

New commits:
commit 15c14abc62d7a46bb4769c452b1cf9f7c2a48c5b
Author: Eike Rathke <erack at redhat.com>
Date:   Tue Feb 13 18:45:09 2018 +0100

    Force CheckLinkFormulaNeedingCheck() only if no ScSetStringParam given
    
    And ensure that if one is given mbCheckLinkFormula is set.
    
    Change-Id: I4eb70825ce4db5a59aa37d98ae40698e4ab81c3c

diff --git a/sc/source/core/data/documentimport.cxx b/sc/source/core/data/documentimport.cxx
index f53bca4cdaaf..a4161d9071f1 100644
--- a/sc/source/core/data/documentimport.cxx
+++ b/sc/source/core/data/documentimport.cxx
@@ -189,6 +189,10 @@ void ScDocumentImport::setAutoInput(const ScAddress& rPos, const OUString& rStr,
     if (!pBlockPos)
         return;
 
+    // If ScSetStringParam was given, ScColumn::ParseString() shall take care
+    // of checking. Ensure caller said so.
+    assert(!pStringParam || pStringParam->mbCheckLinkFormula);
+
     ScCellValue aCell;
     pTab->aCol[rPos.Col()].ParseString(
         aCell, rPos.Row(), rPos.Tab(), rStr, mpImpl->mrDoc.GetAddressConvention(), pStringParam);
@@ -209,7 +213,8 @@ void ScDocumentImport::setAutoInput(const ScAddress& rPos, const OUString& rStr,
             pBlockPos->miCellPos = rCells.set(pBlockPos->miCellPos, rPos.Row(), aCell.mfValue);
         break;
         case CELLTYPE_FORMULA:
-            mpImpl->mrDoc.CheckLinkFormulaNeedingCheck( *aCell.mpFormula->GetCode());
+            if (!pStringParam)
+                mpImpl->mrDoc.CheckLinkFormulaNeedingCheck( *aCell.mpFormula->GetCode());
             // This formula cell instance is directly placed in the document without copying.
             pBlockPos->miCellPos = rCells.set(pBlockPos->miCellPos, rPos.Row(), aCell.mpFormula);
             aCell.mpFormula = nullptr;
commit 60dcdcb82edff93f682586f930b9516c0010f777
Author: Eike Rathke <erack at redhat.com>
Date:   Tue Feb 13 18:32:15 2018 +0100

    Use ScSetStringParam::mbCheckLinkFormula in simple ScImportExport::Text2Doc()
    
    Change-Id: I59f5ebd1056c7c0caa89ba2754e6feaa34cc1a43

diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx
index 088f6d977041..146c097626e1 100644
--- a/sc/source/ui/docshell/impex.cxx
+++ b/sc/source/ui/docshell/impex.cxx
@@ -848,6 +848,9 @@ bool ScImportExport::Text2Doc( SvStream& rStrm )
     pSeps[0] = cSep;
     pSeps[1] = 0;
 
+    ScSetStringParam aSetStringParam;
+    aSetStringParam.mbCheckLinkFormula = true;
+
     SCCOL nStartCol = aRange.aStart.Col();
     SCROW nStartRow = aRange.aStart.Row();
     SCCOL nEndCol = aRange.aEnd.Col();
@@ -897,7 +900,7 @@ bool ScImportExport::Text2Doc( SvStream& rStrm )
                         if (nRow>nEndRow) nEndRow = nRow;
                     }
                     if( bData && nCol <= nEndCol && nRow <= nEndRow )
-                        pDoc->SetString( nCol, nRow, aRange.aStart.Tab(), aCell );
+                        pDoc->SetString( nCol, nRow, aRange.aStart.Tab(), aCell, &aSetStringParam );
                 }
                 else                            // too many columns/rows
                 {
commit bcd62f2050336951ad56892d6e0a42f63c59a674
Author: Eike Rathke <erack at redhat.com>
Date:   Tue Feb 13 18:08:28 2018 +0100

    CheckLinkFormulaNeedingCheck() for ScDocumentImport::setFormulaCell()
    
    Change-Id: I1587be914b390b2597185dd5af870d1d785010a4

diff --git a/sc/source/core/data/documentimport.cxx b/sc/source/core/data/documentimport.cxx
index c86065b881ed..f53bca4cdaaf 100644
--- a/sc/source/core/data/documentimport.cxx
+++ b/sc/source/core/data/documentimport.cxx
@@ -285,6 +285,8 @@ void ScDocumentImport::setFormulaCell(
     std::unique_ptr<ScFormulaCell> pFC =
         o3tl::make_unique<ScFormulaCell>(&mpImpl->mrDoc, rPos, rFormula, eGrammar);
 
+    mpImpl->mrDoc.CheckLinkFormulaNeedingCheck( *pFC->GetCode());
+
     if (pResult)
     {
         // Set cached result to this formula cell.
commit d0a230db23410d68ed55f6518de242f83fe8d1bd
Author: Eike Rathke <erack at redhat.com>
Date:   Tue Feb 13 17:39:34 2018 +0100

    Use ScSetStringParam::mbCheckLinkFormula instead
    
    ... of obtaining the formula cell again.
    
    Change-Id: I37978744577a45c0234d2bfa222e96de548786e6

diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx
index da9d0c7bc9e2..088f6d977041 100644
--- a/sc/source/ui/docshell/impex.cxx
+++ b/sc/source/ui/docshell/impex.cxx
@@ -1213,21 +1213,11 @@ static bool lcl_PutString(
         aParam.mbDetectNumberFormat = bDetectNumFormat;
         aParam.meSetTextNumFormat = ScSetStringParam::SpecialNumberOnly;
         aParam.mbHandleApostrophe = false;
+        aParam.mbCheckLinkFormula = true;
         if ( bUseDocImport )
             rDocImport.setAutoInput(ScAddress(nCol, nRow, nTab), rStr, &aParam);
         else
-        {
             pDoc->SetString( nCol, nRow, nTab, rStr, &aParam );
-            // ScColumn::ParseString() is strict about the first character
-            // having to be '=' for formula, so we can use that here and don't
-            // need to obtain the created cell for each and every value.
-            if (rStr.getLength() > 1 && rStr[0] == '=')
-            {
-                const ScFormulaCell* pFC = pDoc->GetFormulaCell( ScAddress( nCol, nRow, nTab));
-                if (pFC)
-                    pDoc->CheckLinkFormulaNeedingCheck( *pFC->GetCode());
-            }
-        }
     }
     else
     {
commit 98c0bd7ffd008015623b2c5eb8630649394d76f6
Author: Eike Rathke <erack at redhat.com>
Date:   Tue Feb 13 17:16:38 2018 +0100

    ScSetStringParam::mbCheckLinkFormula for HTML and RTF import
    
    Change-Id: I7cf7cf12142322cbffd5160e9a8dce55efd36be5

diff --git a/sc/source/filter/rtf/eeimpars.cxx b/sc/source/filter/rtf/eeimpars.cxx
index 267c84d7cf80..b07ddecf9ae5 100644
--- a/sc/source/filter/rtf/eeimpars.cxx
+++ b/sc/source/filter/rtf/eeimpars.cxx
@@ -341,6 +341,7 @@ void ScEEImport::WriteToDocument( bool bSizeColsRows, double nOutputFactor, SvNu
                 aParam.mbDetectNumberFormat = true;
                 aParam.meSetTextNumFormat = ScSetStringParam::SpecialNumberOnly;
                 aParam.mbHandleApostrophe = false;
+                aParam.mbCheckLinkFormula = true;
 
                 if (!aValStr.isEmpty())
                     mpDoc->SetValue( nCol, nRow, nTab, fVal );
commit 271d9ebfe0c4fc57ea6f01a9c048021e5429dd15
Author: Eike Rathke <erack at redhat.com>
Date:   Tue Feb 13 17:11:47 2018 +0100

    Handle ScSetStringParam::mbCheckLinkFormula in ScColumn::ParseString()
    
    Change-Id: Id6b0705140baacdb872560f7031efaf0c03f0e00

diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 3343ea782383..d42b4479b5d5 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -1727,11 +1727,15 @@ bool ScColumn::ParseString(
             rCell.set(rPool.intern(rString));
         }
         else // = Formula
-            rCell.set(
-                new ScFormulaCell(
+        {
+            ScFormulaCell* pFormulaCell = new ScFormulaCell(
                     GetDoc(), ScAddress(nCol, nRow, nTabP), rString,
                     formula::FormulaGrammar::mergeToGrammar(formula::FormulaGrammar::GRAM_DEFAULT, eConv),
-                    ScMatrixMode::NONE));
+                    ScMatrixMode::NONE);
+            if (aParam.mbCheckLinkFormula)
+                GetDoc()->CheckLinkFormulaNeedingCheck( *pFormulaCell->GetCode());
+            rCell.set( pFormulaCell);
+        }
     }
     else if ( cFirstChar == '\'') // 'Text
     {
commit 5a93c51e3b7f455ff5d4cfc9e8b6e510fc126b75
Author: Eike Rathke <erack at redhat.com>
Date:   Tue Feb 13 17:10:21 2018 +0100

    Introduce ScSetStringParam::mbCheckLinkFormula
    
    Change-Id: I2028fc53f9778606778cd8629611752acd3f1a1c

diff --git a/sc/inc/stringutil.hxx b/sc/inc/stringutil.hxx
index 34c4ce246b9f..ff2bc9cd74cd 100644
--- a/sc/inc/stringutil.hxx
+++ b/sc/inc/stringutil.hxx
@@ -93,6 +93,13 @@ struct SAL_WARN_UNUSED SC_DLLPUBLIC ScSetStringParam
 
     sc::StartListeningType meStartListening;
 
+    /** When true and the string results in a compiled formula, check the
+        formula tokens for presence of functions that could trigger access to
+        external resources. This is to be set to true in import filter code,
+        but not for user input.
+     */
+    bool mbCheckLinkFormula;
+
     ScSetStringParam();
 
     /**
diff --git a/sc/source/core/tool/stringutil.cxx b/sc/source/core/tool/stringutil.cxx
index 62a7f0d53490..ba5923896e38 100644
--- a/sc/source/core/tool/stringutil.cxx
+++ b/sc/source/core/tool/stringutil.cxx
@@ -30,7 +30,8 @@ ScSetStringParam::ScSetStringParam() :
     mbDetectNumberFormat(true),
     meSetTextNumFormat(Never),
     mbHandleApostrophe(true),
-    meStartListening(sc::SingleCellListening)
+    meStartListening(sc::SingleCellListening),
+    mbCheckLinkFormula(false)
 {
 }
 


More information about the Libreoffice-commits mailing list