oox/source/export/drawingml.cxx | 48 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-)
New commits: commit 5f80331513b13ba5ebb0b7362d34d5039698db99 Author: Karthik Godha <[email protected]> AuthorDate: Thu Dec 25 15:11:01 2025 +0530 Commit: Michael Stahl <[email protected]> CommitDate: Tue Jan 6 19:04:36 2026 +0100 tdf#170035:Add OOXML formula check for guidelist Add condition check to skip exported of internal names/equations to OOXML. Change-Id: I0c03bbaa7ea61dd4f526fc0476482571df7e7cf7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196209 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Michael Stahl <[email protected]> (cherry picked from commit 0f0bb6ba234c371e1c5a6420ba1e441322c9c354) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196545 Tested-by: Jenkins diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx index aa650c0d541e..6d93e4a3101c 100644 --- a/oox/source/export/drawingml.cxx +++ b/oox/source/export/drawingml.cxx @@ -39,6 +39,7 @@ #include <sax/fastattribs.hxx> #include <comphelper/diagnose_ex.hxx> #include <comphelper/processfactory.hxx> +#include <comphelper/string.hxx> #include <i18nlangtag/languagetag.hxx> #include <basegfx/matrix/b2dhommatrixtools.hxx> #include <basegfx/range/b2drange.hxx> @@ -46,6 +47,7 @@ #include <numeric> #include <string_view> +#include <set> #include <com/sun/star/awt/CharSet.hpp> #include <com/sun/star/awt/FontDescriptor.hpp> @@ -4932,6 +4934,47 @@ void prepareTextArea(const EnhancedCustomShape2d& rEnhancedCustomShape2d, return; } +bool IsValidOOXMLFormula(std::u16string_view sFormula) +{ + // Accepted Formulas + // "val n1" + // "abs n1" + // "sqrt n1" + // "min n1 n2" + // "max n1 n2" + // "*/ n1 n2 n3" + // "+- n1 n2 n3" + // "?: n1 n2 n3" + + // Below vector contains validTokens for the 1st token based on the number of tokens in the formula. The order is: 2, 3, 4 + const std::vector<std::set<OUString>> validTokens + = { { "val", "abs", "sqrt" }, { "min", "max" }, { "*/", "+-", "?:" } }; + const std::set<OUString> builtInVariables = { "w", "h", "t", "b", "l", "r" }; + const std::vector<OUString> strTokens = comphelper::string::split(sFormula, ' '); + sal_uInt16 nSize = strTokens.size(); + + if (nSize > 1 && nSize < 5) + { + auto aTokens = validTokens[nSize - 2]; + + // Check whether the 1st token is valid + if (aTokens.find(strTokens[0]) == aTokens.end()) + return false; + + // Check that the remaining tokens are either numbers or buit-in variables + for (sal_Int16 i = 1; i < nSize; i++) + { + OUString sVal = strTokens[i]; + sal_Int64 nVal = sVal.toInt64(); + if (builtInVariables.find(sVal) == builtInVariables.end() + && OUString::number(nVal) != sVal) + return false; + } + return true; + } + return false; +} + OUString GetFormula(const OUString& sEquation, const OUString& sReplace, const OUString& sNewStr) { OUString sFormula = sEquation; @@ -4942,7 +4985,10 @@ OUString GetFormula(const OUString& sEquation, const OUString& sReplace, const O sFormula = "*/ " + sModifiedEquation; } - return sFormula; + if (IsValidOOXMLFormula(sFormula)) + return sFormula; + + return OUString(); } void prepareGluePoints(std::vector<Guide>& rGuideList,
