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

ENH PHP 8.1 compatibility #70

Merged
merged 1 commit into from
Apr 26, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Filters/RateLimitFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ protected function getCacheKey($itemkey)

// Add global identifier
if ($this->config()->get('lock_bypage')) {
$key .= '_' . md5($itemkey);
$key .= '_' . md5($itemkey ?? '');
}

// Add user-specific identifier
if ($this->config()->get('lock_byuserip') && Controller::has_curr()) {
$ip = Controller::curr()->getRequest()->getIP();
$key .= '_' . md5($ip);
$key .= '_' . md5($ip ?? '');
}

return $key;
Expand Down
2 changes: 1 addition & 1 deletion src/VersionFeedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function allchanges()
if ($lastChange) {
// Cache the diffs to remove DOS possibility.
$key = 'allchanges'
. preg_replace('#[^a-zA-Z0-9_]#', '', $lastChange['LastEdited'])
. preg_replace('#[^a-zA-Z0-9_]#', '', $lastChange['LastEdited'] ?? '')
. (Security::getCurrentUser() ? Security::getCurrentUser()->ID : 'public');
$changeList = $this->filterContent($key, function () use ($latestChanges) {
$changeList = new ArrayList();
Expand Down
20 changes: 10 additions & 10 deletions tests/VersionFeedFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function testPublicHistoryPublicHistoryDisabled()

$response = $this->get($page->RelativeLink('allchanges'));
$this->assertEquals(200, $response->getStatusCode());
$xml = simplexml_load_string($response->getBody());
$xml = simplexml_load_string($response->getBody() ?? '');
$this->assertFalse(
(bool)$xml->channel->item,
'With Page\'s "PublicHistory" disabled, `allchanges` action should not have an item in the channel'
Expand All @@ -99,15 +99,15 @@ public function testPublicHistoryPublicHistoryEnabled()

$response = $this->get($page->RelativeLink('changes'));
$this->assertEquals(200, $response->getStatusCode());
$xml = simplexml_load_string($response->getBody());
$xml = simplexml_load_string($response->getBody() ?? '');
$this->assertTrue(
(bool)$xml->channel->item,
'With Page\'s "PublicHistory" enabled, `changes` action should have an item in the channel'
);

$response = $this->get($page->RelativeLink('allchanges'));
$this->assertEquals(200, $response->getStatusCode());
$xml = simplexml_load_string($response->getBody());
$xml = simplexml_load_string($response->getBody() ?? '');
$this->assertTrue(
(bool)$xml->channel->item,
'With "PublicHistory" enabled, `allchanges` action should have an item in the channel'
Expand Down Expand Up @@ -141,7 +141,7 @@ public function testRateLimiting()
$page1->ID,
Versioned::get_versionnumber_by_stage(SiteTree::class, 'Live', $page1->ID, false)
]);
$key = RateLimitFilter::CACHE_PREFIX . '_' . md5($key);
$key = RateLimitFilter::CACHE_PREFIX . '_' . md5($key ?? '');
$this->cache->set($key, time() + 10);
$response = $this->get($page1->RelativeLink('changes'));
$this->assertEquals(429, $response->getStatusCode());
Expand Down Expand Up @@ -171,19 +171,19 @@ public function testChangesActionContainsChangesForCurrentPageOnly()
$page2 = $this->createPageWithChanges(['Title' => 'Page2']);

$response = $this->get($page1->RelativeLink('changes'));
$xml = simplexml_load_string($response->getBody());
$xml = simplexml_load_string($response->getBody() ?? '');
$titles = array_map(function ($item) {
return (string)$item->title;
}, $xml->xpath('//item'));
}, $xml->xpath('//item') ?? []);
// TODO Unclear if this should contain the original version
$this->assertContains('Changed: Page1', $titles);
$this->assertNotContains('Changed: Page2', $titles);

$response = $this->get($page2->RelativeLink('changes'));
$xml = simplexml_load_string($response->getBody());
$xml = simplexml_load_string($response->getBody() ?? '');
$titles = array_map(function ($item) {
return (string)$item->title;
}, $xml->xpath('//item'));
}, $xml->xpath('//item') ?? []);
// TODO Unclear if this should contain the original version
$this->assertNotContains('Changed: Page1', $titles);
$this->assertContains('Changed: Page2', $titles);
Expand All @@ -195,10 +195,10 @@ public function testAllChangesActionContainsAllChangesForAllPages()
$page2 = $this->createPageWithChanges(['Title' => 'Page2']);

$response = $this->get($page1->RelativeLink('allchanges'));
$xml = simplexml_load_string($response->getBody());
$xml = simplexml_load_string($response->getBody() ?? '');
$titles = array_map(function ($item) {
return str_replace('Changed: ', '', (string) $item->title);
}, $xml->xpath('//item'));
}, $xml->xpath('//item') ?? []);
$this->assertContains('Page1', $titles);
$this->assertContains('Page2', $titles);
}
Expand Down
6 changes: 3 additions & 3 deletions tests/VersionFeedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ public function testDiffedChangesTitle()

// Strip spaces from test output because they're not reliably maintained by the HTML Tidier
$cleanDiffOutput = function ($val) {
return str_replace(' ', '', strip_tags($val));
return str_replace(' ', '', strip_tags($val ?? ''));
};

$this->assertContains(
str_replace(' ', '', _t('RSSHistory.TITLECHANGED', 'Title has changed:') . 'My Changed Title'),
array_map($cleanDiffOutput, $page->getDiffList()->column('DiffTitle')),
array_map($cleanDiffOutput, $page->getDiffList()->column('DiffTitle') ?? []),
'Detects published title changes'
);

$this->assertNotContains(
str_replace(' ', '', _t('RSSHistory.TITLECHANGED', 'Title has changed:') . 'My Unpublished Changed Title'),
array_map($cleanDiffOutput, $page->getDiffList()->column('DiffTitle')),
array_map($cleanDiffOutput, $page->getDiffList()->column('DiffTitle') ?? []),
'Ignores unpublished title changes'
);
}
Expand Down