diff --git a/CHANGELOG.md b/CHANGELOG.md index 23902379cc..117c87136f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - `Helper\Html` support UTF-8 HTML input - [#444](https://github.com/PHPOffice/PhpSpreadsheet/issues/444) - Xlsx loaded an extra empty comment for each real comment - [#375](https://github.com/PHPOffice/PhpSpreadsheet/issues/375) - Xlsx reader do not read rows and columns filtered out in readFilter at all - [#370](https://github.com/PHPOffice/PhpSpreadsheet/issues/370) +- Fixed parsing of conditionals in COUNTIF functions - [#526](https://github.com/PHPOffice/PhpSpreadsheet/issues/526) ## [1.2.1] - 2018-04-10 diff --git a/src/PhpSpreadsheet/Calculation/Functions.php b/src/PhpSpreadsheet/Calculation/Functions.php index b6389a8df9..bf11ceaf7f 100644 --- a/src/PhpSpreadsheet/Calculation/Functions.php +++ b/src/PhpSpreadsheet/Calculation/Functions.php @@ -277,7 +277,7 @@ public static function ifCondition($condition) return '=' . $condition; } - preg_match('/([<>=]+)(.*)/', $condition, $matches); + preg_match('/(=|<[>=]?|>=?)(.*)/', $condition, $matches); list(, $operator, $operand) = $matches; if (!is_numeric($operand)) { diff --git a/tests/PhpSpreadsheetTests/Calculation/FunctionsTest.php b/tests/PhpSpreadsheetTests/Calculation/FunctionsTest.php index ed85e80c2c..1255d91078 100644 --- a/tests/PhpSpreadsheetTests/Calculation/FunctionsTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/FunctionsTest.php @@ -307,4 +307,20 @@ public function providerIsFormula() { return require 'data/Calculation/Functions/ISFORMULA.php'; } + + /** + * @dataProvider providerIfCondition + * + * @param mixed $expectedResult + */ + public function testIfCondition($expectedResult, ...$args) + { + $result = Functions::ifCondition(...$args); + self::assertEquals($expectedResult, $result); + } + + public function providerIfCondition() + { + return require 'data/Calculation/Functions/IF_CONDITION.php'; + } } diff --git a/tests/data/Calculation/Functions/IF_CONDITION.php b/tests/data/Calculation/Functions/IF_CONDITION.php new file mode 100644 index 0000000000..0b510ed9ec --- /dev/null +++ b/tests/data/Calculation/Functions/IF_CONDITION.php @@ -0,0 +1,36 @@ +"A"', + '>A', + ], + [ + '<="A"', + '<=A', + ], + [ + '>"A"', + '>A', + ], + [ + '>="A"', + '>=A', + ], + [ + '<>"A"', + '<>A', + ], + [ + '<""< PLEASE SELECT >"', + '<>< Please Select >', + ], +];