From bb3ada1cb8caf959000ccb18b419a94795ba9c10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dalibor=20Karlovi=C4=87?= Date: Tue, 7 Aug 2018 09:38:18 +0200 Subject: [PATCH] fix: allow iterators to go out of bounds with prev() Fixes #587. --- CHANGELOG.md | 6 ++++++ src/PhpSpreadsheet/Worksheet/ColumnCellIterator.php | 4 ---- src/PhpSpreadsheet/Worksheet/RowIterator.php | 6 ------ .../Worksheet/ColumnCellIteratorTest.php | 2 -- tests/PhpSpreadsheetTests/Worksheet/RowIteratorTest.php | 2 -- 5 files changed, 6 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42e6fc2023..5e5b0f810a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## Upcoming + +### Fixed + +- Allow iterators to go out of bounds with prev - [#587](https://github.com/PHPOffice/PhpSpreadsheet/issues/587) + ## [1.4.0] - 2018-08-06 ### Added diff --git a/src/PhpSpreadsheet/Worksheet/ColumnCellIterator.php b/src/PhpSpreadsheet/Worksheet/ColumnCellIterator.php index a4cdb6f49b..e6501ee693 100644 --- a/src/PhpSpreadsheet/Worksheet/ColumnCellIterator.php +++ b/src/PhpSpreadsheet/Worksheet/ColumnCellIterator.php @@ -153,10 +153,6 @@ public function next() */ public function prev() { - if ($this->currentRow <= $this->startRow) { - throw new PhpSpreadsheetException("Row is already at the beginning of range ({$this->startRow} - {$this->endRow})"); - } - do { --$this->currentRow; } while (($this->onlyExistingCells) && diff --git a/src/PhpSpreadsheet/Worksheet/RowIterator.php b/src/PhpSpreadsheet/Worksheet/RowIterator.php index 70b7b8f7d7..838cd471f8 100644 --- a/src/PhpSpreadsheet/Worksheet/RowIterator.php +++ b/src/PhpSpreadsheet/Worksheet/RowIterator.php @@ -152,15 +152,9 @@ public function next() /** * Set the iterator to its previous value. - * - * @throws PhpSpreadsheetException */ public function prev() { - if ($this->position <= $this->startRow) { - throw new PhpSpreadsheetException("Row is already at the beginning of range ({$this->startRow} - {$this->endRow})"); - } - --$this->position; } diff --git a/tests/PhpSpreadsheetTests/Worksheet/ColumnCellIteratorTest.php b/tests/PhpSpreadsheetTests/Worksheet/ColumnCellIteratorTest.php index 46880e2e11..f315865d23 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/ColumnCellIteratorTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/ColumnCellIteratorTest.php @@ -78,8 +78,6 @@ public function testSeekOutOfRange() public function testPrevOutOfRange() { - $this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class); - $iterator = new ColumnCellIterator($this->mockWorksheet, 'A', 2, 4); $iterator->prev(); } diff --git a/tests/PhpSpreadsheetTests/Worksheet/RowIteratorTest.php b/tests/PhpSpreadsheetTests/Worksheet/RowIteratorTest.php index 63e26b34f9..6936818bad 100644 --- a/tests/PhpSpreadsheetTests/Worksheet/RowIteratorTest.php +++ b/tests/PhpSpreadsheetTests/Worksheet/RowIteratorTest.php @@ -75,8 +75,6 @@ public function testSeekOutOfRange() public function testPrevOutOfRange() { - $this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class); - $iterator = new RowIterator($this->mockWorksheet, 2, 4); $iterator->prev(); }