Return false if the zip entry could not be located

Previously the function did not check whether the return value of `ZipArchive::locateName`
was `false`. And when it was, it was passed straight into `ZipArchive::getFromIndex`,
which casts it to an integer, resulting in it incorrectly retrieving the entry at index `0`.

Fixes #262
Closes #268
This commit is contained in:
anton-harvey 2017-11-01 23:16:32 +00:00 committed by Adrien Crivelli
parent 8183c71e78
commit f7518dadc9
No known key found for this signature in database
GPG Key ID: B182FD79DC6DE92E
2 changed files with 3 additions and 6 deletions

View File

@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Control characters in cell values are automatically escaped - [#212](https://github.com/PHPOffice/PhpSpreadsheet/issues/212)
- Prevent color changing when copy/pasting xls files written by PhpSpreadsheet to another file - @al-lala [#218](https://github.com/PHPOffice/PhpSpreadsheet/issues/218)
- Add cell reference automatic when there is no cell reference('r' attribute) in Xlsx file. - @GreatHumorist [#225](https://github.com/PHPOffice/PhpSpreadsheet/pull/225) Refer to [issue#201](https://github.com/PHPOffice/PhpSpreadsheet/issues/201)
- `Reader\Xlsx::getFromZipArchive()` function return false if the zip entry could not be located. - @anton-harvey [#268](https://github.com/PHPOffice/PhpSpreadsheet/pull/268)
### BREAKING CHANGE

View File

@ -308,13 +308,9 @@ class Xlsx extends BaseReader
// so we need to load case-insensitively from the zip file
// Apache POI fixes
$contents = $archive->getFromIndex(
$archive->locateName($fileName, ZipArchive::FL_NOCASE)
);
$contents = $archive->getFromName($fileName, 0, ZipArchive::FL_NOCASE);
if ($contents === false) {
$contents = $archive->getFromIndex(
$archive->locateName(substr($fileName, 1), ZipArchive::FL_NOCASE)
);
$contents = $archive->getFromName(substr($fileName, 1), 0, ZipArchive::FL_NOCASE);
}
return $contents;