Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RowIterator::prev() should not throw an exception if you go out of bounds #587

Closed
dkarlovi opened this issue Jul 9, 2018 · 0 comments
Closed

Comments

@dkarlovi
Copy link
Contributor

dkarlovi commented Jul 9, 2018

This is:

- [x] a bug report
- [ ] a feature request
- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpspreadsheet or https://gitter.im/PHPOffice/PhpSpreadsheet)

What is the expected behavior?

RowIterator::prev() not throwing an exception if you go out of bounds.

What is the current behavior?

RowIterator::prev() throwing an exception if you go out of bounds.

What are the steps to reproduce?

I've implemented an RowIterator decorator which allows me to iterate in reverse,
https://github.com/dkarlovi/xls-transmailifier/blob/command/src/Transmailifier/ReverseRowIterator.php#L63

The way current code works, it will throw an exception if you try to go out of bounds:

if ($this->position <= $this->startRow) {
throw new PhpSpreadsheetException("Row is already at the beginning of range ({$this->startRow} - {$this->endRow})");
}

But, how iterators work, they WILL go out of bounds and then call valid(). You can see this by having next() not check if it's out of bounds, it just does.

I believe this to be a bug.

Which versions of PhpSpreadsheet and PHP are affected?

Latest master, as linked.

dkarlovi added a commit to dkarlovi/PhpSpreadsheet that referenced this issue Aug 7, 2018
dkarlovi added a commit to dkarlovi/PhpSpreadsheet that referenced this issue Aug 7, 2018
Dfred pushed a commit to Dfred/PhpSpreadsheet that referenced this issue Nov 20, 2018
Iterators prev() behavior is now consistent with next(), meaning
that it can go out of bounds and it must be validated with valid()
before using it.

Fixes PHPOffice#587
Fixes PHPOffice#627
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant