* 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)
This commit is contained in:
lucasnetau 2021-12-05 03:07:18 +11:00 committed by GitHub
parent 3918f626cc
commit e01a81ec5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 4 deletions

View File

@ -25,13 +25,13 @@ class WildcardMatch
public static function wildcard(string $wildcard): string public static function wildcard(string $wildcard): string
{ {
// Preg Escape the wildcard, but protecting the Excel * and ? search characters // 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 === '') { if ($value === '' || $value === null) {
return true; return false;
} }
return (bool) preg_match("/^{$wildcard}\$/mui", $value); return (bool) preg_match("/^{$wildcard}\$/mui", $value);

View File

@ -352,4 +352,10 @@ return [
['aAAAAA', 'a123456*c', 'abc~xyz', 'alembic'], ['aAAAAA', 'a123456*c', 'abc~xyz', 'alembic'],
0, 0,
], ],
[
2, // Expected
'abc/123*', // wildcard search contains a forward slash
['abc123fff', 'abc/123fff'],
0,
],
]; ];

View File

@ -168,4 +168,16 @@ return [
'n', 'n',
[[1], [2], [3], [4], [5], [6], [7], [8], [9]], [[1], [2], [3], [4], [5], [6], [7], [8], [9]],
], ],
[
2,
[
[null],
['abc123fff'],
],
'abc123*',
[
[1],
[2],
],
],
]; ];