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

Fixes #801 libxml_disable_entity_loader() is changed #802

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 src/PhpSpreadsheet/IOFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public static function createReaderForFile($filename)
if ($reader->canRead($filename)) {
return $reader;
}
unset($reader);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Reader/Security/XmlScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class XmlScanner
private $libxmlDisableEntityLoader = false;

/**
* Store the initial setting of libxmlDisableEntityLoader so that we can resore t later.
* Stores the initial setting of libxmlDisableEntityLoader so that we can restore it later.
*
* @var bool
*/
Expand Down
32 changes: 32 additions & 0 deletions tests/PhpSpreadsheetTests/IOFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Reader;
use PhpOffice\PhpSpreadsheet\Shared\File;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -144,4 +145,35 @@ public function testRegisterInvalidReader()

IOFactory::registerReader('foo', 'bar');
}

/**
* @dataProvider providerBoolean
*
* @param bool $startWith
*/
public function testLibxmlEntityLoaderValue($startWith)
{
$filename = tempnam(File::sysGetTempDir(), 'phpspreadsheet-test');

$valueBeforeTest = libxml_disable_entity_loader($startWith);

try {
IOFactory::createReaderForFile($filename);
self::assertFalse(true);
} catch (\Exception $e) {
}
$finalValue = libxml_disable_entity_loader($valueBeforeTest);
self::assertSame(
$startWith,
$finalValue,
sprintf('Started with: %b value at the end: %b', $startWith, $finalValue)
);

unlink($filename);
}

public function providerBoolean()
{
return [[true], [false]];
}
}