Skip to content

Commit b77352f

Browse files
Jean85PowerKiKi
authored andcommitted
Add regex delimiter for proper escaping
1 parent b5057f4 commit b77352f

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

src/PhpSpreadsheet/Calculation/Calculation.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2360,10 +2360,10 @@ public function _translateFormulaToLocale($formula)
23602360
if (self::$functionReplaceFromExcel === null) {
23612361
self::$functionReplaceFromExcel = [];
23622362
foreach (array_keys(self::$localeFunctions) as $excelFunctionName) {
2363-
self::$functionReplaceFromExcel[] = '/(@?[^\w\.])' . preg_quote($excelFunctionName) . '([\s]*\()/Ui';
2363+
self::$functionReplaceFromExcel[] = '/(@?[^\w\.])' . preg_quote($excelFunctionName, '/') . '([\s]*\()/Ui';
23642364
}
23652365
foreach (array_keys(self::$localeBoolean) as $excelBoolean) {
2366-
self::$functionReplaceFromExcel[] = '/(@?[^\w\.])' . preg_quote($excelBoolean) . '([^\w\.])/Ui';
2366+
self::$functionReplaceFromExcel[] = '/(@?[^\w\.])' . preg_quote($excelBoolean, '/') . '([^\w\.])/Ui';
23672367
}
23682368
}
23692369

@@ -2388,10 +2388,10 @@ public function _translateFormulaToEnglish($formula)
23882388
if (self::$functionReplaceFromLocale === null) {
23892389
self::$functionReplaceFromLocale = [];
23902390
foreach (array_values(self::$localeFunctions) as $localeFunctionName) {
2391-
self::$functionReplaceFromLocale[] = '/(@?[^\w\.])' . preg_quote($localeFunctionName) . '([\s]*\()/Ui';
2391+
self::$functionReplaceFromLocale[] = '/(@?[^\w\.])' . preg_quote($localeFunctionName, '/') . '([\s]*\()/Ui';
23922392
}
23932393
foreach (array_values(self::$localeBoolean) as $excelBoolean) {
2394-
self::$functionReplaceFromLocale[] = '/(@?[^\w\.])' . preg_quote($excelBoolean) . '([^\w\.])/Ui';
2394+
self::$functionReplaceFromLocale[] = '/(@?[^\w\.])' . preg_quote($excelBoolean, '/') . '([^\w\.])/Ui';
23952395
}
23962396
}
23972397

src/PhpSpreadsheet/Cell/AdvancedValueBinder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public function bindValue(Cell $cell, $value = null)
9191
$currencyCode = StringHelper::getCurrencyCode();
9292
$decimalSeparator = StringHelper::getDecimalSeparator();
9393
$thousandsSeparator = StringHelper::getThousandsSeparator();
94-
if (preg_match('/^' . preg_quote($currencyCode) . ' *(\d{1,3}(' . preg_quote($thousandsSeparator) . '\d{3})*|(\d+))(' . preg_quote($decimalSeparator) . '\d{2})?$/', $value)) {
94+
if (preg_match('/^' . preg_quote($currencyCode, '/') . ' *(\d{1,3}(' . preg_quote($thousandsSeparator, '/') . '\d{3})*|(\d+))(' . preg_quote($decimalSeparator, '/') . '\d{2})?$/', $value)) {
9595
// Convert value to number
9696
$value = (float) trim(str_replace([$currencyCode, $thousandsSeparator, $decimalSeparator], ['', '', '.'], $value));
9797
$cell->setValueExplicit($value, DataType::TYPE_NUMERIC);

src/PhpSpreadsheet/ReferenceHelper.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -654,8 +654,8 @@ public function updateFormulaReferences($pFormula = '', $pBefore = 'A1', $pNumCo
654654
$row = 10000000 + trim($match[3], '$');
655655
$cellIndex = $column . $row;
656656

657-
$newCellTokens[$cellIndex] = preg_quote($toString);
658-
$cellTokens[$cellIndex] = '/(?<!\d\$\!)' . preg_quote($fromString) . '(?!\d)/i';
657+
$newCellTokens[$cellIndex] = preg_quote($toString, '/');
658+
$cellTokens[$cellIndex] = '/(?<!\d\$\!)' . preg_quote($fromString, '/') . '(?!\d)/i';
659659
++$adjustCount;
660660
}
661661
}
@@ -679,8 +679,8 @@ public function updateFormulaReferences($pFormula = '', $pBefore = 'A1', $pNumCo
679679
$row = 10000000;
680680
$cellIndex = $column . $row;
681681

682-
$newCellTokens[$cellIndex] = preg_quote($toString);
683-
$cellTokens[$cellIndex] = '/(?<![A-Z\$\!])' . preg_quote($fromString) . '(?![A-Z])/i';
682+
$newCellTokens[$cellIndex] = preg_quote($toString, '/');
683+
$cellTokens[$cellIndex] = '/(?<![A-Z\$\!])' . preg_quote($fromString, '/') . '(?![A-Z])/i';
684684
++$adjustCount;
685685
}
686686
}
@@ -705,8 +705,8 @@ public function updateFormulaReferences($pFormula = '', $pBefore = 'A1', $pNumCo
705705
$row = trim($row, '$') + 10000000;
706706
$cellIndex = $column . $row;
707707

708-
$newCellTokens[$cellIndex] = preg_quote($toString);
709-
$cellTokens[$cellIndex] = '/(?<![A-Z]\$\!)' . preg_quote($fromString) . '(?!\d)/i';
708+
$newCellTokens[$cellIndex] = preg_quote($toString, '/');
709+
$cellTokens[$cellIndex] = '/(?<![A-Z]\$\!)' . preg_quote($fromString, '/') . '(?!\d)/i';
710710
++$adjustCount;
711711
}
712712
}
@@ -731,8 +731,8 @@ public function updateFormulaReferences($pFormula = '', $pBefore = 'A1', $pNumCo
731731
$row = trim($row, '$') + 10000000;
732732
$cellIndex = $row . $column;
733733

734-
$newCellTokens[$cellIndex] = preg_quote($toString);
735-
$cellTokens[$cellIndex] = '/(?<![A-Z\$\!])' . preg_quote($fromString) . '(?!\d)/i';
734+
$newCellTokens[$cellIndex] = preg_quote($toString, '/');
735+
$cellTokens[$cellIndex] = '/(?<![A-Z\$\!])' . preg_quote($fromString, '/') . '(?!\d)/i';
736736
++$adjustCount;
737737
}
738738
}

0 commit comments

Comments
 (0)