diff --git a/CHANGELOG.md b/CHANGELOG.md index f80307d3..8d56aae4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,11 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Added support for inline styles in Html reader (borders, alignment, width, height) - QuotedText cells no longer treated as formulae if the content begins with a `=` - Clean handling for DDE in formulae + +### Fixed + - Fix handling for escaped enclosures and new lines in CSV Separator Inference +- Fix MATCH an error was appearing when comparing strings against 0 (always true) ## [1.6.0] - 2019-01-02 diff --git a/src/PhpSpreadsheet/Calculation/LookupRef.php b/src/PhpSpreadsheet/Calculation/LookupRef.php index 2a3c5582..b71313ee 100644 --- a/src/PhpSpreadsheet/Calculation/LookupRef.php +++ b/src/PhpSpreadsheet/Calculation/LookupRef.php @@ -522,9 +522,13 @@ class LookupRef if ($matchType == 0 || $matchType == 1) { foreach ($lookupArray as $i => $lookupArrayValue) { - if (($matchType == 0) && ($lookupArrayValue == $lookupValue)) { + $onlyNumeric = is_numeric($lookupArrayValue) && is_numeric($lookupValue); + $onlyNumericExactMatch = $onlyNumeric && $lookupArrayValue == $lookupValue; + $nonOnlyNumericExactMatch = !$onlyNumeric && $lookupArrayValue === $lookupValue; + $exactMatch = $onlyNumericExactMatch || $nonOnlyNumericExactMatch; + if (($matchType == 0) && $exactMatch) { // exact match - return ++$i; + return $i + 1; } elseif (($matchType == 1) && ($lookupArrayValue <= $lookupValue)) { $i = array_search($i, $keySet); diff --git a/tests/data/Calculation/LookupRef/MATCH.php b/tests/data/Calculation/LookupRef/MATCH.php index a82acdde..84644949 100644 --- a/tests/data/Calculation/LookupRef/MATCH.php +++ b/tests/data/Calculation/LookupRef/MATCH.php @@ -96,4 +96,13 @@ return [ [8, 8, 3, 2], -1, ], + + // 0s are causing errors, because things like 0 == 'x' is true. Thanks PHP! + [ + 3, + 'x', + [[0], [0], ['x'], ['x'], ['x']], + 0 + ], + ];