Compare commits

...

2 Commits

Author SHA1 Message Date
Guy Sartorelli
f93f32d22b
Merge pull request #70 from creative-commoners/pulls/2/php81
ENH PHP 8.1 compatibility
2022-04-26 17:57:34 +12:00
Steve Boyd
600a4b2cde ENH PHP 8.1 compatibility 2022-04-13 13:53:29 +12:00
4 changed files with 16 additions and 16 deletions

View File

@ -68,13 +68,13 @@ class RateLimitFilter extends ContentFilter
// Add global identifier // Add global identifier
if ($this->config()->get('lock_bypage')) { if ($this->config()->get('lock_bypage')) {
$key .= '_' . md5($itemkey); $key .= '_' . md5($itemkey ?? '');
} }
// Add user-specific identifier // Add user-specific identifier
if ($this->config()->get('lock_byuserip') && Controller::has_curr()) { if ($this->config()->get('lock_byuserip') && Controller::has_curr()) {
$ip = Controller::curr()->getRequest()->getIP(); $ip = Controller::curr()->getRequest()->getIP();
$key .= '_' . md5($ip); $key .= '_' . md5($ip ?? '');
} }
return $key; return $key;

View File

@ -119,7 +119,7 @@ class VersionFeedController extends Extension
if ($lastChange) { if ($lastChange) {
// Cache the diffs to remove DOS possibility. // Cache the diffs to remove DOS possibility.
$key = 'allchanges' $key = 'allchanges'
. preg_replace('#[^a-zA-Z0-9_]#', '', $lastChange['LastEdited']) . preg_replace('#[^a-zA-Z0-9_]#', '', $lastChange['LastEdited'] ?? '')
. (Security::getCurrentUser() ? Security::getCurrentUser()->ID : 'public'); . (Security::getCurrentUser() ? Security::getCurrentUser()->ID : 'public');
$changeList = $this->filterContent($key, function () use ($latestChanges) { $changeList = $this->filterContent($key, function () use ($latestChanges) {
$changeList = new ArrayList(); $changeList = new ArrayList();

View File

@ -86,7 +86,7 @@ class VersionFeedFunctionalTest extends FunctionalTest
$response = $this->get($page->RelativeLink('allchanges')); $response = $this->get($page->RelativeLink('allchanges'));
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$xml = simplexml_load_string($response->getBody()); $xml = simplexml_load_string($response->getBody() ?? '');
$this->assertFalse( $this->assertFalse(
(bool)$xml->channel->item, (bool)$xml->channel->item,
'With Page\'s "PublicHistory" disabled, `allchanges` action should not have an item in the channel' 'With Page\'s "PublicHistory" disabled, `allchanges` action should not have an item in the channel'
@ -99,7 +99,7 @@ class VersionFeedFunctionalTest extends FunctionalTest
$response = $this->get($page->RelativeLink('changes')); $response = $this->get($page->RelativeLink('changes'));
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$xml = simplexml_load_string($response->getBody()); $xml = simplexml_load_string($response->getBody() ?? '');
$this->assertTrue( $this->assertTrue(
(bool)$xml->channel->item, (bool)$xml->channel->item,
'With Page\'s "PublicHistory" enabled, `changes` action should have an item in the channel' 'With Page\'s "PublicHistory" enabled, `changes` action should have an item in the channel'
@ -107,7 +107,7 @@ class VersionFeedFunctionalTest extends FunctionalTest
$response = $this->get($page->RelativeLink('allchanges')); $response = $this->get($page->RelativeLink('allchanges'));
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$xml = simplexml_load_string($response->getBody()); $xml = simplexml_load_string($response->getBody() ?? '');
$this->assertTrue( $this->assertTrue(
(bool)$xml->channel->item, (bool)$xml->channel->item,
'With "PublicHistory" enabled, `allchanges` action should have an item in the channel' 'With "PublicHistory" enabled, `allchanges` action should have an item in the channel'
@ -141,7 +141,7 @@ class VersionFeedFunctionalTest extends FunctionalTest
$page1->ID, $page1->ID,
Versioned::get_versionnumber_by_stage(SiteTree::class, 'Live', $page1->ID, false) 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); $this->cache->set($key, time() + 10);
$response = $this->get($page1->RelativeLink('changes')); $response = $this->get($page1->RelativeLink('changes'));
$this->assertEquals(429, $response->getStatusCode()); $this->assertEquals(429, $response->getStatusCode());
@ -171,19 +171,19 @@ class VersionFeedFunctionalTest extends FunctionalTest
$page2 = $this->createPageWithChanges(['Title' => 'Page2']); $page2 = $this->createPageWithChanges(['Title' => 'Page2']);
$response = $this->get($page1->RelativeLink('changes')); $response = $this->get($page1->RelativeLink('changes'));
$xml = simplexml_load_string($response->getBody()); $xml = simplexml_load_string($response->getBody() ?? '');
$titles = array_map(function ($item) { $titles = array_map(function ($item) {
return (string)$item->title; return (string)$item->title;
}, $xml->xpath('//item')); }, $xml->xpath('//item') ?? []);
// TODO Unclear if this should contain the original version // TODO Unclear if this should contain the original version
$this->assertContains('Changed: Page1', $titles); $this->assertContains('Changed: Page1', $titles);
$this->assertNotContains('Changed: Page2', $titles); $this->assertNotContains('Changed: Page2', $titles);
$response = $this->get($page2->RelativeLink('changes')); $response = $this->get($page2->RelativeLink('changes'));
$xml = simplexml_load_string($response->getBody()); $xml = simplexml_load_string($response->getBody() ?? '');
$titles = array_map(function ($item) { $titles = array_map(function ($item) {
return (string)$item->title; return (string)$item->title;
}, $xml->xpath('//item')); }, $xml->xpath('//item') ?? []);
// TODO Unclear if this should contain the original version // TODO Unclear if this should contain the original version
$this->assertNotContains('Changed: Page1', $titles); $this->assertNotContains('Changed: Page1', $titles);
$this->assertContains('Changed: Page2', $titles); $this->assertContains('Changed: Page2', $titles);
@ -195,10 +195,10 @@ class VersionFeedFunctionalTest extends FunctionalTest
$page2 = $this->createPageWithChanges(['Title' => 'Page2']); $page2 = $this->createPageWithChanges(['Title' => 'Page2']);
$response = $this->get($page1->RelativeLink('allchanges')); $response = $this->get($page1->RelativeLink('allchanges'));
$xml = simplexml_load_string($response->getBody()); $xml = simplexml_load_string($response->getBody() ?? '');
$titles = array_map(function ($item) { $titles = array_map(function ($item) {
return str_replace('Changed: ', '', (string) $item->title); return str_replace('Changed: ', '', (string) $item->title);
}, $xml->xpath('//item')); }, $xml->xpath('//item') ?? []);
$this->assertContains('Page1', $titles); $this->assertContains('Page1', $titles);
$this->assertContains('Page2', $titles); $this->assertContains('Page2', $titles);
} }

View File

@ -44,18 +44,18 @@ class VersionFeedTest extends SapphireTest
// Strip spaces from test output because they're not reliably maintained by the HTML Tidier // Strip spaces from test output because they're not reliably maintained by the HTML Tidier
$cleanDiffOutput = function ($val) { $cleanDiffOutput = function ($val) {
return str_replace(' ', '', strip_tags($val)); return str_replace(' ', '', strip_tags($val ?? ''));
}; };
$this->assertContains( $this->assertContains(
str_replace(' ', '', _t('RSSHistory.TITLECHANGED', 'Title has changed:') . 'My Changed Title'), 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' 'Detects published title changes'
); );
$this->assertNotContains( $this->assertNotContains(
str_replace(' ', '', _t('RSSHistory.TITLECHANGED', 'Title has changed:') . 'My Unpublished Changed Title'), 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' 'Ignores unpublished title changes'
); );
} }