diff --git a/CHANGELOG.md b/CHANGELOG.md index 22b73339..8d73781d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Better auto-detection of CSV separators - [#305](https://github.com/PHPOffice/PhpSpreadsheet/issues/305) - Support for shape style ending with `;` - [#304](https://github.com/PHPOffice/PhpSpreadsheet/issues/304) - Freeze Panes takes wrong coordinates for XLSX - [#322](https://github.com/PHPOffice/PhpSpreadsheet/issues/322) +- `COLUMNS` and `ROWS` functions crashed in some cases - [#336](https://github.com/PHPOffice/PhpSpreadsheet/issues/336) ## [1.0.0] - 2017-12-25 diff --git a/src/PhpSpreadsheet/Calculation/Calculation.php b/src/PhpSpreadsheet/Calculation/Calculation.php index a5d40d01..3d44b4ed 100644 --- a/src/PhpSpreadsheet/Calculation/Calculation.php +++ b/src/PhpSpreadsheet/Calculation/Calculation.php @@ -2784,11 +2784,11 @@ class Calculation /** * Read the dimensions of a matrix, and re-index it with straight numeric keys starting from row 0, column 0. * - * @param mixed &$matrix matrix operand + * @param array &$matrix matrix operand * * @return int[] An array comprising the number of rows, and number of columns */ - private static function getMatrixDimensions(&$matrix) + public static function getMatrixDimensions(array &$matrix) { $matrixRows = count($matrix); $matrixColumns = 0; diff --git a/src/PhpSpreadsheet/Calculation/LookupRef.php b/src/PhpSpreadsheet/Calculation/LookupRef.php index 6c1a71a7..029e7ea6 100644 --- a/src/PhpSpreadsheet/Calculation/LookupRef.php +++ b/src/PhpSpreadsheet/Calculation/LookupRef.php @@ -138,7 +138,7 @@ class LookupRef reset($cellAddress); $isMatrix = (is_numeric(key($cellAddress))); - list($columns, $rows) = Calculation::_getMatrixDimensions($cellAddress); + list($columns, $rows) = Calculation::getMatrixDimensions($cellAddress); if ($isMatrix) { return $rows; @@ -218,7 +218,7 @@ class LookupRef reset($cellAddress); $isMatrix = (is_numeric(key($cellAddress))); - list($columns, $rows) = Calculation::_getMatrixDimensions($cellAddress); + list($columns, $rows) = Calculation::getMatrixDimensions($cellAddress); if ($isMatrix) { return $columns; diff --git a/tests/PhpSpreadsheetTests/Calculation/LookupRefTest.php b/tests/PhpSpreadsheetTests/Calculation/LookupRefTest.php index 6881c114..eef15e3a 100644 --- a/tests/PhpSpreadsheetTests/Calculation/LookupRefTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/LookupRefTest.php @@ -79,4 +79,36 @@ class LookupRefTest extends TestCase { return require 'data/Calculation/LookupRef/INDEX.php'; } + + /** + * @dataProvider providerCOLUMNS + * + * @param mixed $expectedResult + */ + public function testCOLUMNS($expectedResult, ...$args) + { + $result = LookupRef::COLUMNS(...$args); + self::assertEquals($expectedResult, $result); + } + + public function providerCOLUMNS() + { + return require 'data/Calculation/LookupRef/COLUMNS.php'; + } + + /** + * @dataProvider providerROWS + * + * @param mixed $expectedResult + */ + public function testROWS($expectedResult, ...$args) + { + $result = LookupRef::ROWS(...$args); + self::assertEquals($expectedResult, $result); + } + + public function providerROWS() + { + return require 'data/Calculation/LookupRef/ROWS.php'; + } } diff --git a/tests/data/Calculation/LookupRef/COLUMNS.php b/tests/data/Calculation/LookupRef/COLUMNS.php new file mode 100644 index 00000000..3a6a587c --- /dev/null +++ b/tests/data/Calculation/LookupRef/COLUMNS.php @@ -0,0 +1,36 @@ + [1, 1]], + ], +]; diff --git a/tests/data/Calculation/LookupRef/ROWS.php b/tests/data/Calculation/LookupRef/ROWS.php new file mode 100644 index 00000000..93808299 --- /dev/null +++ b/tests/data/Calculation/LookupRef/ROWS.php @@ -0,0 +1,36 @@ + [1, 1]], + ], +];