Add regex delimiter for proper escaping

This commit is contained in:
Alessandro Lai 2017-12-22 10:19:36 +01:00 committed by Adrien Crivelli
parent b5057f44b1
commit b77352f153
No known key found for this signature in database
GPG Key ID: B182FD79DC6DE92E
3 changed files with 13 additions and 13 deletions

View File

@ -2360,10 +2360,10 @@ class Calculation
if (self::$functionReplaceFromExcel === null) { if (self::$functionReplaceFromExcel === null) {
self::$functionReplaceFromExcel = []; self::$functionReplaceFromExcel = [];
foreach (array_keys(self::$localeFunctions) as $excelFunctionName) { foreach (array_keys(self::$localeFunctions) as $excelFunctionName) {
self::$functionReplaceFromExcel[] = '/(@?[^\w\.])' . preg_quote($excelFunctionName) . '([\s]*\()/Ui'; self::$functionReplaceFromExcel[] = '/(@?[^\w\.])' . preg_quote($excelFunctionName, '/') . '([\s]*\()/Ui';
} }
foreach (array_keys(self::$localeBoolean) as $excelBoolean) { foreach (array_keys(self::$localeBoolean) as $excelBoolean) {
self::$functionReplaceFromExcel[] = '/(@?[^\w\.])' . preg_quote($excelBoolean) . '([^\w\.])/Ui'; self::$functionReplaceFromExcel[] = '/(@?[^\w\.])' . preg_quote($excelBoolean, '/') . '([^\w\.])/Ui';
} }
} }
@ -2388,10 +2388,10 @@ class Calculation
if (self::$functionReplaceFromLocale === null) { if (self::$functionReplaceFromLocale === null) {
self::$functionReplaceFromLocale = []; self::$functionReplaceFromLocale = [];
foreach (array_values(self::$localeFunctions) as $localeFunctionName) { foreach (array_values(self::$localeFunctions) as $localeFunctionName) {
self::$functionReplaceFromLocale[] = '/(@?[^\w\.])' . preg_quote($localeFunctionName) . '([\s]*\()/Ui'; self::$functionReplaceFromLocale[] = '/(@?[^\w\.])' . preg_quote($localeFunctionName, '/') . '([\s]*\()/Ui';
} }
foreach (array_values(self::$localeBoolean) as $excelBoolean) { foreach (array_values(self::$localeBoolean) as $excelBoolean) {
self::$functionReplaceFromLocale[] = '/(@?[^\w\.])' . preg_quote($excelBoolean) . '([^\w\.])/Ui'; self::$functionReplaceFromLocale[] = '/(@?[^\w\.])' . preg_quote($excelBoolean, '/') . '([^\w\.])/Ui';
} }
} }

View File

@ -91,7 +91,7 @@ class AdvancedValueBinder extends DefaultValueBinder implements IValueBinder
$currencyCode = StringHelper::getCurrencyCode(); $currencyCode = StringHelper::getCurrencyCode();
$decimalSeparator = StringHelper::getDecimalSeparator(); $decimalSeparator = StringHelper::getDecimalSeparator();
$thousandsSeparator = StringHelper::getThousandsSeparator(); $thousandsSeparator = StringHelper::getThousandsSeparator();
if (preg_match('/^' . preg_quote($currencyCode) . ' *(\d{1,3}(' . preg_quote($thousandsSeparator) . '\d{3})*|(\d+))(' . preg_quote($decimalSeparator) . '\d{2})?$/', $value)) { if (preg_match('/^' . preg_quote($currencyCode, '/') . ' *(\d{1,3}(' . preg_quote($thousandsSeparator, '/') . '\d{3})*|(\d+))(' . preg_quote($decimalSeparator, '/') . '\d{2})?$/', $value)) {
// Convert value to number // Convert value to number
$value = (float) trim(str_replace([$currencyCode, $thousandsSeparator, $decimalSeparator], ['', '', '.'], $value)); $value = (float) trim(str_replace([$currencyCode, $thousandsSeparator, $decimalSeparator], ['', '', '.'], $value));
$cell->setValueExplicit($value, DataType::TYPE_NUMERIC); $cell->setValueExplicit($value, DataType::TYPE_NUMERIC);

View File

@ -654,8 +654,8 @@ class ReferenceHelper
$row = 10000000 + trim($match[3], '$'); $row = 10000000 + trim($match[3], '$');
$cellIndex = $column . $row; $cellIndex = $column . $row;
$newCellTokens[$cellIndex] = preg_quote($toString); $newCellTokens[$cellIndex] = preg_quote($toString, '/');
$cellTokens[$cellIndex] = '/(?<!\d\$\!)' . preg_quote($fromString) . '(?!\d)/i'; $cellTokens[$cellIndex] = '/(?<!\d\$\!)' . preg_quote($fromString, '/') . '(?!\d)/i';
++$adjustCount; ++$adjustCount;
} }
} }
@ -679,8 +679,8 @@ class ReferenceHelper
$row = 10000000; $row = 10000000;
$cellIndex = $column . $row; $cellIndex = $column . $row;
$newCellTokens[$cellIndex] = preg_quote($toString); $newCellTokens[$cellIndex] = preg_quote($toString, '/');
$cellTokens[$cellIndex] = '/(?<![A-Z\$\!])' . preg_quote($fromString) . '(?![A-Z])/i'; $cellTokens[$cellIndex] = '/(?<![A-Z\$\!])' . preg_quote($fromString, '/') . '(?![A-Z])/i';
++$adjustCount; ++$adjustCount;
} }
} }
@ -705,8 +705,8 @@ class ReferenceHelper
$row = trim($row, '$') + 10000000; $row = trim($row, '$') + 10000000;
$cellIndex = $column . $row; $cellIndex = $column . $row;
$newCellTokens[$cellIndex] = preg_quote($toString); $newCellTokens[$cellIndex] = preg_quote($toString, '/');
$cellTokens[$cellIndex] = '/(?<![A-Z]\$\!)' . preg_quote($fromString) . '(?!\d)/i'; $cellTokens[$cellIndex] = '/(?<![A-Z]\$\!)' . preg_quote($fromString, '/') . '(?!\d)/i';
++$adjustCount; ++$adjustCount;
} }
} }
@ -731,8 +731,8 @@ class ReferenceHelper
$row = trim($row, '$') + 10000000; $row = trim($row, '$') + 10000000;
$cellIndex = $row . $column; $cellIndex = $row . $column;
$newCellTokens[$cellIndex] = preg_quote($toString); $newCellTokens[$cellIndex] = preg_quote($toString, '/');
$cellTokens[$cellIndex] = '/(?<![A-Z\$\!])' . preg_quote($fromString) . '(?!\d)/i'; $cellTokens[$cellIndex] = '/(?<![A-Z\$\!])' . preg_quote($fromString, '/') . '(?!\d)/i';
++$adjustCount; ++$adjustCount;
} }
} }