diff --git a/src/PhpSpreadsheet/Calculation/TextData/Extract.php b/src/PhpSpreadsheet/Calculation/TextData/Extract.php index 519607c080..24ddff2ec5 100644 --- a/src/PhpSpreadsheet/Calculation/TextData/Extract.php +++ b/src/PhpSpreadsheet/Calculation/TextData/Extract.php @@ -261,7 +261,7 @@ private static function buildDelimiter($delimiter): string $delimiter = Functions::flattenArray($delimiter); $quotedDelimiters = array_map( function ($delimiter) { - return preg_quote($delimiter ?? ''); + return preg_quote($delimiter ?? '', '/'); }, $delimiter ); @@ -270,7 +270,7 @@ function ($delimiter) { return '(' . $delimiters . ')'; } - return '(' . preg_quote($delimiter ?? '') . ')'; + return '(' . preg_quote($delimiter ?? '', '/') . ')'; } private static function matchFlags(int $matchMode): string diff --git a/src/PhpSpreadsheet/Calculation/TextData/Format.php b/src/PhpSpreadsheet/Calculation/TextData/Format.php index 06433e4b13..57d3316637 100644 --- a/src/PhpSpreadsheet/Calculation/TextData/Format.php +++ b/src/PhpSpreadsheet/Calculation/TextData/Format.php @@ -294,7 +294,7 @@ public static function NUMBERVALUE($value = '', $decimalSeparator = null, $group } if (!is_numeric($value)) { - $decimalPositions = preg_match_all('/' . preg_quote($decimalSeparator) . '/', $value, $matches, PREG_OFFSET_CAPTURE); + $decimalPositions = preg_match_all('/' . preg_quote($decimalSeparator, '/') . '/', $value, $matches, PREG_OFFSET_CAPTURE); if ($decimalPositions > 1) { return ExcelError::VALUE(); } diff --git a/src/PhpSpreadsheet/Calculation/TextData/Text.php b/src/PhpSpreadsheet/Calculation/TextData/Text.php index 8e6a575a29..b8a730767c 100644 --- a/src/PhpSpreadsheet/Calculation/TextData/Text.php +++ b/src/PhpSpreadsheet/Calculation/TextData/Text.php @@ -193,7 +193,7 @@ private static function buildDelimiter($delimiter): string if (is_array($delimiter) && count($valueSet) > 1) { $quotedDelimiters = array_map( function ($delimiter) { - return preg_quote($delimiter ?? ''); + return preg_quote($delimiter ?? '', '/'); }, $valueSet ); @@ -202,7 +202,7 @@ function ($delimiter) { return '(' . $delimiters . ')'; } - return '(' . preg_quote(/** @scrutinizer ignore-type */ Functions::flattenSingleValue($delimiter)) . ')'; + return '(' . preg_quote(/** @scrutinizer ignore-type */ Functions::flattenSingleValue($delimiter), '/') . ')'; } private static function matchFlags(bool $matchMode): string diff --git a/tests/data/Calculation/TextData/NUMBERVALUE.php b/tests/data/Calculation/TextData/NUMBERVALUE.php index e72194067f..6131317426 100644 --- a/tests/data/Calculation/TextData/NUMBERVALUE.php +++ b/tests/data/Calculation/TextData/NUMBERVALUE.php @@ -51,6 +51,8 @@ ], 'no arguments' => ['exception'], 'boolean argument' => ['#VALUE!', true], + 'slash as group separator' => [1234567.1, '1/234/567.1', '.', '/'], + 'slash as decimal separator' => [1234567.1, '1,234,567/1', '/', ','], 'issue 3574 null string treated as 0' => [0, '', ',', ' '], 'issue 3574 one or more spaces treated as 0' => [0, ' ', ',', ' '], 'issue 3574 non-blank numeric string okay' => [2, ' 2 ', ',', ' '], diff --git a/tests/data/Calculation/TextData/TEXTAFTER.php b/tests/data/Calculation/TextData/TEXTAFTER.php index ebcfecb946..c0e3e3d51f 100644 --- a/tests/data/Calculation/TextData/TEXTAFTER.php +++ b/tests/data/Calculation/TextData/TEXTAFTER.php @@ -248,4 +248,11 @@ 1, ], ], + 'slash delimiter' => [ + 'about/that', + [ + 'How/about/that', + '/', + ], + ], ]; diff --git a/tests/data/Calculation/TextData/TEXTBEFORE.php b/tests/data/Calculation/TextData/TEXTBEFORE.php index 1929354ce5..a79d37b0fd 100644 --- a/tests/data/Calculation/TextData/TEXTBEFORE.php +++ b/tests/data/Calculation/TextData/TEXTBEFORE.php @@ -240,4 +240,11 @@ 1, ], ], + 'slash delimiter' => [ + 'How', + [ + 'How/about/that', + '/', + ], + ], ]; diff --git a/tests/data/Calculation/TextData/TEXTSPLIT.php b/tests/data/Calculation/TextData/TEXTSPLIT.php index 64016ca7a7..a10b26f6e8 100644 --- a/tests/data/Calculation/TextData/TEXTSPLIT.php +++ b/tests/data/Calculation/TextData/TEXTSPLIT.php @@ -104,4 +104,20 @@ '', ], ], + 'slash as column delimiter' => [ + [['Hello', 'World']], + [ + 'Hello/World', + '/', + '', + ], + ], + 'slash as row delimiter' => [ + [['ho', 'w'], ['about', '#N/A'], ['t', 'hat']], + [ + 'ho.w/about/t.hat', + '.', + '/', + ], + ], ];