Skip to content

Bugfix for issue: xls file cause the exception during open by Xls reader #402 #659

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

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Fixed

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

## [1.4.1] - 2018-09-30
Expand Down
8 changes: 0 additions & 8 deletions src/PhpSpreadsheet/Shared/OLERead.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,14 +326,6 @@ 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) {
// Invalid position
throw new ReaderException('Parameter pos=' . $pos . ' is invalid.');
}

$len = strlen($data);
if ($len < $pos + 4) {
$data .= str_repeat("\0", $pos + 4 - $len);
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.