Skip to content

Commit

Permalink
Settings: deleted libxml_disable_entity_loader() calls since they're …
Browse files Browse the repository at this point in the history
…not necessary.

Prevent setLibXmlLoaderOptions() and getLibXmlLoaderOptions() to call the libxml_disable_entity_loader() function which alter the global state of libxml.
See the discussion here PHPOffice#74
  • Loading branch information
agopaul committed Mar 12, 2017
1 parent de57bf7 commit 6a0a5d9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/PhpSpreadsheet/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ public static function setLibXmlLoaderOptions($options = null)
if (is_null($options) && defined('LIBXML_DTDLOAD')) {
$options = LIBXML_DTDLOAD | LIBXML_DTDATTR;
}
@libxml_disable_entity_loader((bool) $options);
self::$libXmlLoaderOptions = $options;
}

Expand All @@ -254,7 +253,6 @@ public static function getLibXmlLoaderOptions()
} elseif (is_null(self::$libXmlLoaderOptions)) {
self::$libXmlLoaderOptions = true;
}
@libxml_disable_entity_loader((bool) self::$libXmlLoaderOptions);

return self::$libXmlLoaderOptions;
}
Expand Down
14 changes: 14 additions & 0 deletions tests/PhpSpreadsheetTests/SettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,34 @@

class SettingsTest extends \PHPUnit_Framework_TestCase
{
/**
* @var string
*/
protected $prevValue;

public function setUp()
{
$this->prevValue = libxml_disable_entity_loader();
libxml_disable_entity_loader(false); // Enable entity loader
}

protected function tearDown()
{
libxml_disable_entity_loader($this->prevValue);
}

public function testGetXMLSettings()
{
$result = \PhpOffice\PhpSpreadsheet\Settings::getLibXmlLoaderOptions();
$this->assertTrue((bool) ((LIBXML_DTDLOAD | LIBXML_DTDATTR) & $result));
$this->assertFalse(libxml_disable_entity_loader());
}

public function testSetXMLSettings()
{
\PhpOffice\PhpSpreadsheet\Settings::setLibXmlLoaderOptions(LIBXML_DTDLOAD | LIBXML_DTDATTR | LIBXML_DTDVALID);
$result = \PhpOffice\PhpSpreadsheet\Settings::getLibXmlLoaderOptions();
$this->assertTrue((bool) ((LIBXML_DTDLOAD | LIBXML_DTDATTR | LIBXML_DTDVALID) & $result));
$this->assertFalse(libxml_disable_entity_loader());
}
}

0 comments on commit 6a0a5d9

Please sign in to comment.