Skip to content

Commit

Permalink
Xls file threw exception during open by Xls reader
Browse files Browse the repository at this point in the history
Ignore some exception in property, if stream is empty

Fixes #402
Fixes #659
  • Loading branch information
bayzhanov authored and PowerKiKi committed Oct 7, 2018
1 parent ae9dd13 commit 08b4456
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed

- Sheet title can contain exclamation mark - [#325](https://github.com/PHPOffice/PhpSpreadsheet/issues/325)
- Xls file cause the exception during open by Xls reader - [#402](https://github.com/PHPOffice/PhpSpreadsheet/issues/402)

## [1.4.1] - 2018-09-30

Expand Down
5 changes: 1 addition & 4 deletions src/PhpSpreadsheet/Shared/OLERead.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,7 @@ private function readPropertySets()
*/
private static function getInt4d($data, $pos)
{
if (trim($data) == '') {
// No data provided
throw new ReaderException('Parameter data is empty.');
} elseif ($pos < 0) {
if ($pos < 0) {
// Invalid position
throw new ReaderException('Parameter pos=' . $pos . ' is invalid.');
}
Expand Down
20 changes: 20 additions & 0 deletions tests/PhpSpreadsheetTests/Reader/XlsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace PhpOffice\PhpSpreadsheetTests\Reader;

use PhpOffice\PhpSpreadsheet\Reader\Xls;
use PHPUnit\Framework\TestCase;

class XlsTest extends TestCase
{
/**
* Test load Xls file.
*/
public function testLoadXlsSample()
{
$filename = './data/Reader/XLS/sample.xls';
$reader = new Xls();
$spreadsheet = $reader->load($filename);
self::assertEquals('Title', $spreadsheet->getSheet(0)->getCell('A1')->getValue());
}
}
28 changes: 28 additions & 0 deletions tests/PhpSpreadsheetTests/Shared/OLEReadTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace PhpOffice\PhpSpreadsheetTests\Shared;

use PhpOffice\PhpSpreadsheet\Shared\OLERead;
use PHPUnit\Framework\TestCase;

class OLEReadTest extends TestCase
{
public function testReadOleStreams()
{
$dataDir = './data/Shared/OLERead/';
$ole = new OLERead();
$ole->read('./data/Reader/XLS/sample.xls');
self::assertEquals(
file_get_contents($dataDir . 'wrkbook'),
$ole->getStream($ole->wrkbook)
);
self::assertEquals(
file_get_contents($dataDir . 'summary'),
$ole->getStream($ole->summaryInformation)
);
self::assertEquals(
file_get_contents($dataDir . 'document'),
$ole->getStream($ole->documentSummaryInformation)
);
}
}
Binary file added tests/data/Reader/XLS/sample.xls
Binary file not shown.
Empty file.
Empty file.
Binary file added tests/data/Shared/OLERead/wrkbook
Binary file not shown.

0 comments on commit 08b4456

Please sign in to comment.