mirror of
https://github.com/silverstripe/silverstripe-externallinks.git
synced 2024-10-22 17:05:44 +02:00
Compare commits
2 Commits
3fc084a1f0
...
164032af76
Author | SHA1 | Date | |
---|---|---|---|
|
164032af76 | ||
|
1bfaf12909 |
@ -101,7 +101,7 @@ class CheckExternalLinksTask extends BuildTask
|
||||
{
|
||||
$class = $link->getAttribute('class');
|
||||
$href = $link->getAttribute('href');
|
||||
$markedBroken = preg_match('/\b(ss-broken)\b/', $class);
|
||||
$markedBroken = preg_match('/\b(ss-broken)\b/', $class ?? '');
|
||||
|
||||
// Check link
|
||||
$httpCode = $this->linkChecker->checkLink($href);
|
||||
@ -127,9 +127,9 @@ class CheckExternalLinksTask extends BuildTask
|
||||
if ($foundBroken) {
|
||||
$class .= ' ss-broken';
|
||||
} else {
|
||||
$class = preg_replace('/\s*\b(ss-broken)\b\s*/', ' ', $class);
|
||||
$class = preg_replace('/\s*\b(ss-broken)\b\s*/', ' ', $class ?? '');
|
||||
}
|
||||
$link->setAttribute('class', trim($class));
|
||||
$link->setAttribute('class', trim($class ?? ''));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -147,7 +147,7 @@ class CheckExternalLinksTask extends BuildTask
|
||||
|
||||
// do we have any whitelisted codes
|
||||
$ignoreCodes = $this->config()->get('ignore_codes');
|
||||
if (is_array($ignoreCodes) && in_array($httpCode, $ignoreCodes)) {
|
||||
if (is_array($ignoreCodes) && in_array($httpCode, $ignoreCodes ?? [])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -58,11 +58,11 @@ class CurlLinkChecker implements LinkChecker
|
||||
public function checkLink($href)
|
||||
{
|
||||
// Skip non-external links
|
||||
if (!preg_match('/^https?[^:]*:\/\//', $href)) {
|
||||
if (!preg_match('/^https?[^:]*:\/\//', $href ?? '')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$cacheKey = md5($href);
|
||||
$cacheKey = md5($href ?? '');
|
||||
if (!$this->config()->get('bypass_cache')) {
|
||||
// Check if we have a cached result
|
||||
$result = $this->getCache()->get($cacheKey, false);
|
||||
|
@ -68,7 +68,7 @@ class ExternalLinksTest extends SapphireTest
|
||||
'http://www.broken.com/url/thing',
|
||||
'http://www.nodomain.com'
|
||||
),
|
||||
array_values($links->map('ID', 'Link')->toArray())
|
||||
array_values($links->map('ID', 'Link')->toArray() ?? [])
|
||||
);
|
||||
|
||||
// Check response codes are correct
|
||||
|
Loading…
Reference in New Issue
Block a user