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

Update to support PHP 8.0 #29

Merged
merged 16 commits into from Oct 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -6,3 +6,4 @@
/laminas-mkdoc-theme/
/phpunit.xml
/vendor/
/.phpunit.result.cache
29 changes: 8 additions & 21 deletions .travis.yml
Expand Up @@ -13,41 +13,28 @@ env:
matrix:
fast_finish: true
include:
- php: 5.6
env:
- DEPS=lowest
- php: 5.6
env:
- DEPS=latest
- php: 7
- php: 7.3
env:
- DEPS=lowest
- php: 7
- php: 7.3
env:
- DEPS=latest
- php: 7.1
- php: 7.4
env:
- DEPS=lowest
- php: 7.1
- php: 7.4
env:
- DEPS=latest
- CS_CHECK=true
- TEST_COVERAGE=true
- php: 7.2
- php: nightly
env:
- DEPS=lowest
- php: 7.2
env:
- DEPS=latest
- php: 7.3
env:
- DEPS=lowest
- php: 7.3
env:
- DEPS=latest
- php: 7.4
- COMPOSER_ARGS="--no-interaction --ignore-platform-reqs"
- php: nightly
env:
- DEPS=latest
- COMPOSER_ARGS="--no-interaction --ignore-platform-reqs"

before_install:
- if [[ $TEST_COVERAGE != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
Expand Down
9 changes: 6 additions & 3 deletions composer.json
Expand Up @@ -21,7 +21,7 @@
"extra": {
},
"require": {
"php": "^5.6 || ^7.0",
"php": "^7.3 || ~8.0.0",
"ext-dom": "*",
"ext-libxml": "*",
"laminas/laminas-escaper": "^2.5.2",
Expand All @@ -33,11 +33,14 @@
"laminas/laminas-coding-standard": "~1.0.0",
"laminas/laminas-db": "^2.8.2",
"laminas/laminas-http": "^2.7",
"laminas/laminas-servicemanager": "^2.7.8 || ^3.3",
"laminas/laminas-servicemanager": "^3.3",
"laminas/laminas-validator": "^2.10.1",
"phpunit/phpunit": "^5.7.27 || ^6.5.14 || ^7.5.20",
"phpunit/phpunit": "^9.3",
"psr/http-message": "^1.0.1"
},
"conflict": {
"laminas/laminas-servicemanager": "<3.3"
},
"suggest": {
"laminas/laminas-cache": "Laminas\\Cache component, for optionally caching feeds between requests",
"laminas/laminas-db": "Laminas\\Db component, for use with PubSubHubbub",
Expand Down
36 changes: 15 additions & 21 deletions phpunit.xml.dist
@@ -1,23 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
backupGlobals="true"
colors="true">
<testsuites>
<testsuite name="laminas-feed Test Suite">
<directory>./test</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>

<php>
<env name="TESTS_LAMINAS_FEED_PUBSUBHUBBUB_BASEURI" value="false" />
<env name="TESTS_LAMINAS_FEED_READER_ONLINE_ENABLED" value="false" />
</php>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="vendor/autoload.php" backupGlobals="true" colors="true">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="laminas-feed Test Suite">
<directory>./test</directory>
</testsuite>
</testsuites>
<php>
<env name="TESTS_LAMINAS_FEED_PUBSUBHUBBUB_BASEURI" value="false"/>
<env name="TESTS_LAMINAS_FEED_READER_ONLINE_ENABLED" value="false"/>
</php>
</phpunit>
3 changes: 2 additions & 1 deletion src/Reader/Http/Response.php
Expand Up @@ -9,6 +9,7 @@
namespace Laminas\Feed\Reader\Http;

use Laminas\Feed\Reader\Exception;
use function is_string;

class Response implements HeaderAwareResponseInterface
{
Expand Down Expand Up @@ -79,7 +80,7 @@ public function getHeaderLine($name, $default = null)
*/
private function validateStatusCode($statusCode)
{
if (! is_numeric($statusCode)) {
if (! is_numeric($statusCode) || (is_string($statusCode) && trim($statusCode) !== $statusCode)) {
throw new Exception\InvalidArgumentException(sprintf(
'%s expects a numeric status code; received %s',
__CLASS__,
Expand Down
48 changes: 33 additions & 15 deletions src/Reader/Reader.php
Expand Up @@ -89,6 +89,24 @@ class Reader implements ReaderImportInterface
],
];

/**
* Disable the ability to load external XML entities based on libxml version
*
* If we are using libxml < 2.9, unsafe XML entity loading must be
* disabled with a flag.
*
* If we are using libxml >= 2.9, XML entity loading is disabled by default.
*
* @return bool
*/
public static function disableEntityLoader($flag = true)
{
if (LIBXML_VERSION < 20900) {
return libxml_disable_entity_loader($flag);
}
ocean marked this conversation as resolved.
Show resolved Hide resolved
return $flag;
}

/**
* Get the Feed cache
*
Expand Down Expand Up @@ -314,18 +332,18 @@ public static function importString($string)
throw new Exception\InvalidArgumentException('Only non empty strings are allowed as input');
}

$libxmlErrflag = libxml_use_internal_errors(true);
$oldValue = libxml_disable_entity_loader(true);
$dom = new DOMDocument();
$status = $dom->loadXML(trim($string));
$libxmlErrflag = libxml_use_internal_errors(true);
$disableEntityLoaderFlag = self::disableEntityLoader();
$dom = new DOMDocument();
$status = $dom->loadXML(trim($string));
foreach ($dom->childNodes as $child) {
if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
throw new Exception\InvalidArgumentException(
'Invalid XML: Detected use of illegal DOCTYPE'
);
}
}
libxml_disable_entity_loader($oldValue);
self::disableEntityLoader($disableEntityLoaderFlag);
libxml_use_internal_errors($libxmlErrflag);

if (! $status) {
Expand Down Expand Up @@ -393,12 +411,12 @@ public static function findFeedLinks($uri)
"Failed to access $uri, got response code " . $response->getStatusCode()
);
}
$responseHtml = $response->getBody();
$libxmlErrflag = libxml_use_internal_errors(true);
$oldValue = libxml_disable_entity_loader(true);
$dom = new DOMDocument();
$status = $dom->loadHTML(trim($responseHtml));
libxml_disable_entity_loader($oldValue);
$responseHtml = $response->getBody();
$libxmlErrflag = libxml_use_internal_errors(true);
$disableEntityLoaderFlag = self::disableEntityLoader();
$dom = new DOMDocument();
$status = $dom->loadHTML(trim($responseHtml));
self::disableEntityLoader($disableEntityLoaderFlag);
libxml_use_internal_errors($libxmlErrflag);
if (! $status) {
// Build error message
Expand Down Expand Up @@ -435,17 +453,17 @@ public static function detectType($feed, $specOnly = false)
} elseif (is_string($feed) && ! empty($feed)) {
ErrorHandler::start(E_NOTICE | E_WARNING);
ini_set('track_errors', 1);
$oldValue = libxml_disable_entity_loader(true);
$dom = new DOMDocument();
$status = $dom->loadXML($feed);
$disableEntityLoaderFlag = self::disableEntityLoader();
$dom = new DOMDocument();
$status = $dom->loadXML($feed);
foreach ($dom->childNodes as $child) {
if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
throw new Exception\InvalidArgumentException(
'Invalid XML: Detected use of illegal DOCTYPE'
);
}
}
libxml_disable_entity_loader($oldValue);
self::disableEntityLoader($disableEntityLoaderFlag);
ini_restore('track_errors');
ErrorHandler::stop();
if (! $status) {
Expand Down
2 changes: 1 addition & 1 deletion test/PubSubHubbub/Model/SubscriptionTest.php
Expand Up @@ -41,7 +41,7 @@ public function testAllOperations()

$this->assertTrue($subscription->hasSubscription($id));
$dataSubscription = $subscription->getSubscription($id);
$this->assertInternalType('array', $dataSubscription);
$this->assertIsArray($dataSubscription);
$keys = [
'id',
'topic_url',
Expand Down
2 changes: 1 addition & 1 deletion test/PubSubHubbub/PublisherTest.php
Expand Up @@ -24,7 +24,7 @@ class PublisherTest extends TestCase
/** @var Publisher */
protected $publisher;

protected function setUp()
protected function setUp(): void
{
$client = new HttpClient();
PubSubHubbub::setHttpClient($client);
Expand Down
2 changes: 1 addition & 1 deletion test/PubSubHubbub/Subscriber/CallbackTest.php
Expand Up @@ -46,7 +46,7 @@ class CallbackTest extends TestCase
/** @var DateTime */
public $now;

protected function setUp()
protected function setUp(): void
{
$this->_callback = new CallbackSubscriber();

Expand Down
2 changes: 1 addition & 1 deletion test/PubSubHubbub/SubscriberHttpTest.php
Expand Up @@ -41,7 +41,7 @@ class SubscriberHttpTest extends TestCase

protected $storage;

protected function setUp()
protected function setUp(): void
{
$this->baseuri = getenv('TESTS_LAMINAS_FEED_PUBSUBHUBBUB_BASEURI');
if ($this->baseuri) {
Expand Down
2 changes: 1 addition & 1 deletion test/PubSubHubbub/SubscriberTest.php
Expand Up @@ -31,7 +31,7 @@ class SubscriberTest extends TestCase

protected $tableGateway;

protected function setUp()
protected function setUp(): void
{
$client = new HttpClient();
PubSubHubbub::setHttpClient($client);
Expand Down
2 changes: 1 addition & 1 deletion test/Reader/Entry/AtomStandaloneEntryTest.php
Expand Up @@ -26,7 +26,7 @@ class AtomStandaloneEntryTest extends TestCase

protected $expectedCatsDc = [];

protected function setUp()
protected function setUp(): void
{
Reader\Reader::reset();
$this->feedSamplePath = dirname(__FILE__) . '/_files/AtomStandaloneEntry';
Expand Down
2 changes: 1 addition & 1 deletion test/Reader/Entry/AtomTest.php
Expand Up @@ -25,7 +25,7 @@ class AtomTest extends TestCase

protected $expectedCatsDc = [];

protected function setUp()
protected function setUp(): void
{
Reader\Reader::reset();
$this->feedSamplePath = dirname(__FILE__) . '/_files/Atom';
Expand Down
2 changes: 1 addition & 1 deletion test/Reader/Entry/CommonTest.php
Expand Up @@ -24,7 +24,7 @@ class CommonTest extends TestCase
{
protected $feedSamplePath;

protected function setUp()
protected function setUp(): void
{
Reader\Reader::reset();
$this->feedSamplePath = dirname(__FILE__) . '/_files/Common';
Expand Down
2 changes: 1 addition & 1 deletion test/Reader/Entry/RssTest.php
Expand Up @@ -27,7 +27,7 @@ class RssTest extends TestCase

protected $expectedCatsAtom = [];

protected function setUp()
protected function setUp(): void
{
Reader\Reader::reset();
$this->feedSamplePath = dirname(__FILE__) . '/_files/Rss';
Expand Down
2 changes: 1 addition & 1 deletion test/Reader/Feed/AtomSourceTest.php
Expand Up @@ -27,7 +27,7 @@ class AtomSourceTest extends TestCase

protected $expectedCatsDc = [];

protected function setUp()
protected function setUp(): void
{
Reader\Reader::reset();
$this->feedSamplePath = dirname(__FILE__) . '/_files/AtomSource';
Expand Down
2 changes: 1 addition & 1 deletion test/Reader/Feed/AtomTest.php
Expand Up @@ -26,7 +26,7 @@ class AtomTest extends TestCase

protected $expectedCatsDc = [];

protected function setUp()
protected function setUp(): void
{
Reader\Reader::reset();
$this->feedSamplePath = dirname(__FILE__) . '/_files/Atom';
Expand Down
2 changes: 1 addition & 1 deletion test/Reader/Feed/CommonTest.php
Expand Up @@ -23,7 +23,7 @@ class CommonTest extends TestCase
{
protected $feedSamplePath;

protected function setUp()
protected function setUp(): void
{
Reader\Reader::reset();
$this->feedSamplePath = dirname(__FILE__) . '/_files/Common';
Expand Down
2 changes: 1 addition & 1 deletion test/Reader/Feed/RssTest.php
Expand Up @@ -26,7 +26,7 @@ class RssTest extends TestCase

protected $expectedCatsAtom = [];

protected function setUp()
protected function setUp(): void
{
Reader\Reader::reset();
$this->feedSamplePath = dirname(__FILE__) . '/_files/Rss';
Expand Down
2 changes: 1 addition & 1 deletion test/Reader/FeedSetTest.php
Expand Up @@ -19,7 +19,7 @@ class FeedSetTest extends TestCase
*/
protected $feedSet;

protected function setUp()
protected function setUp(): void
{
$this->feedSet = new FeedSet();
}
Expand Down