Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Handle a wildcard match that contains a forward slash in the pattern by adding / to the delimiter list of preg_quote
* Fix SUMIF doing a wildcard match on empty cells (NULL)
* Fix compare logic to return false when value is an empty string or NULL (Verified against LibreOffice SUMIF and MATCH handling of empty cells)
  • Loading branch information
lucasnetau committed Dec 2, 2021
1 parent 580c741 commit dbd800e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/PhpSpreadsheet/Calculation/Internal/WildcardMatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class WildcardMatch
public static function wildcard(string $wildcard): string
{
// Preg Escape the wildcard, but protecting the Excel * and ? search characters
return str_replace(self::SEARCH_SET, self::REPLACEMENT_SET, preg_quote($wildcard));
return str_replace(self::SEARCH_SET, self::REPLACEMENT_SET, preg_quote($wildcard, '/'));
}

public static function compare(string $value, string $wildcard): bool
public static function compare(?string $value, string $wildcard): bool
{
if ($value === '') {
return true;
if ($value === '' || $value === null) {
return false;
}

return (bool) preg_match("/^{$wildcard}\$/mui", $value);
Expand Down
6 changes: 6 additions & 0 deletions tests/data/Calculation/LookupRef/MATCH.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,4 +352,10 @@
['aAAAAA', 'a123456*c', 'abc~xyz', 'alembic'],
0,
],
[
2, // Expected
'abc/123*', // wildcard search contains a forward slash
['abc123fff', 'abc/123fff'],
0,
],
];
12 changes: 12 additions & 0 deletions tests/data/Calculation/MathTrig/SUMIF.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,16 @@
'n',
[[1], [2], [3], [4], [5], [6], [7], [8], [9]],
],
[
2,
[
[null],
['abc123fff'],
],
'abc123*',
[
[1],
[2],
],
],
];

0 comments on commit dbd800e

Please sign in to comment.