don't process link if it's null

don't process body of feed if it's null

Co-authored-by: Sean Molenaar <SMillerDev@users.noreply.github.com>
Signed-off-by: Benjamin Brahmer <info@b-brahmer.de>
This commit is contained in:
Benjamin Brahmer 2023-01-11 16:43:27 +01:00
parent 41264586ea
commit 502e4b923e
2 changed files with 23 additions and 15 deletions

View File

@ -326,13 +326,16 @@ class Feed extends Entity implements IAPI, \JsonSerializable
'basicAuthPassword'
]);
if (is_null($this->link)) {
return $serialized;
}
$url = parse_url($this->link, PHP_URL_HOST);
// strip leading www. to avoid css class confusion
if (strpos($url, 'www.') === 0) {
$url = substr($url, 4);
}
$serialized['cssClass'] = 'custom-' . str_replace('.', '-', $url);
return $serialized;
@ -488,6 +491,9 @@ class Feed extends Entity implements IAPI, \JsonSerializable
*/
public function setLink(?string $link = null): Feed
{
if (is_null($link)) {
return $this;
}
$link = trim($link);
if (strpos($link, 'http') === 0 && $this->link !== $link) {
$this->link = $link;

View File

@ -301,22 +301,24 @@ class FeedFetcher implements IFeedFetcher
}
// purification is done in the service layer
$body = mb_convert_encoding(
$body,
'HTML-ENTITIES',
mb_detect_encoding($body)
);
if (strpos($body, 'CDATA') !== false) {
libxml_use_internal_errors(true);
$data = simplexml_load_string(
"<?xml version=\"1.0\"?><item>$body</item>",
SimpleXMLElement::class,
LIBXML_NOCDATA
if (!is_null($body)) {
$body = mb_convert_encoding(
$body,
'HTML-ENTITIES',
mb_detect_encoding($body)
);
if ($data !== false && libxml_get_last_error() === false) {
$body = (string) $data;
if (strpos($body, 'CDATA') !== false) {
libxml_use_internal_errors(true);
$data = simplexml_load_string(
"<?xml version=\"1.0\"?><item>$body</item>",
SimpleXMLElement::class,
LIBXML_NOCDATA
);
if ($data !== false && libxml_get_last_error() === false) {
$body = (string) $data;
}
libxml_clear_errors();
}
libxml_clear_errors();
}
$item->setBody($body);