From 44fb2c98bcc49d5d83186abc2dc05bf9b6eba60c Mon Sep 17 00:00:00 2001 From: Dag Date: Fri, 13 Oct 2023 00:26:11 +0200 Subject: [PATCH] fix: various fixes (#3745) --- bridges/CVEDetailsBridge.php | 2 +- bridges/CubariBridge.php | 18 ++++++++++-------- lib/FeedParser.php | 7 +++++-- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/bridges/CVEDetailsBridge.php b/bridges/CVEDetailsBridge.php index 27b4008ce24..b52d290ea6f 100644 --- a/bridges/CVEDetailsBridge.php +++ b/bridges/CVEDetailsBridge.php @@ -57,7 +57,7 @@ public function collectData() $content = $tr->find('.cvesummarylong', 0)->innertext; $cweList = $detailHtml->find('h2', 2)->next_sibling(); foreach ($cweList->find('li') as $li) { - $cweWithDescription = $li->find('a', 0)->innertext; + $cweWithDescription = $li->find('a', 0)->innertext ?? ''; if (preg_match('/CWE-(\d+)/', $cweWithDescription, $cwe)) { $categories[] = 'CWE-' . $cwe[1]; diff --git a/bridges/CubariBridge.php b/bridges/CubariBridge.php index 9a08dbbac2b..a7b6d69def2 100644 --- a/bridges/CubariBridge.php +++ b/bridges/CubariBridge.php @@ -47,8 +47,8 @@ public function getURI() */ public function collectData() { - $jsonSite = getContents($this->getInput('gist')); - $jsonFile = json_decode($jsonSite, true); + $json = getContents($this->getInput('gist')); + $jsonFile = json_decode($json, true); $this->mangaTitle = $jsonFile['title']; @@ -66,12 +66,14 @@ protected function getEncodedGist() { $url = $this->getInput('gist'); - preg_match('/\/([a-z]*)\.githubusercontent.com(.*)/', $url, $matches); - - // raw or gist is first match. - $unencoded = $matches[1] . $matches[2]; - - return base64_encode($unencoded); + if (preg_match('/\/([a-z]*)\.githubusercontent.com(.*)/', $url, $matches)) { + // raw or gist is first match. + $unencoded = $matches[1] . $matches[2]; + return base64_encode($unencoded); + } else { + // todo: fix this + return ''; + } } private function getSanitizedHash($string) diff --git a/lib/FeedParser.php b/lib/FeedParser.php index 90df548da3d..a9aabde053d 100644 --- a/lib/FeedParser.php +++ b/lib/FeedParser.php @@ -64,7 +64,7 @@ public function parseFeed(string $xmlString): array $feed['items'][] = $this->parseAtomItem($item); } } else { - throw new \Exception(sprintf('Unable to detect feed format from `%s`', $url)); + throw new \Exception('Unable to detect feed format'); } return $feed; @@ -163,7 +163,9 @@ public function parseRss2Item(\SimpleXMLElement $feedItem): array } if (isset($feedItem->enclosure) && !empty($feedItem->enclosure['url'])) { - $item['enclosures'] = [(string)$feedItem->enclosure['url']]; + $item['enclosures'] = [ + (string)$feedItem->enclosure['url'], + ]; } return $item; } @@ -189,6 +191,7 @@ public function parseRss091Item(\SimpleXMLElement $feedItem): array { $item = []; if (isset($feedItem->link)) { + // todo: trim uri $item['uri'] = (string)$feedItem->link; } if (isset($feedItem->title)) {