Better validate input JSON fetched from Wikipedia

This commit is contained in:
Joshua Ramon Enslin 2024-11-12 15:36:32 +01:00
parent c72ad51dda
commit 4dcd93b947
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE

View File

@ -151,7 +151,11 @@ final class NodaWikidataFetcher {
private static function _getCleanedWikipediaSnippet(string $lang, string $title):string { private static function _getCleanedWikipediaSnippet(string $lang, string $title):string {
$datafromwiki = MD_STD::runCurl(self::_getWikipediaApiLink($lang, $title), 10000); $datafromwiki = MD_STD::runCurl(self::_getWikipediaApiLink($lang, $title), 10000);
$datafromwiki = strval(json_decode($datafromwiki, true)['parse']['text']['*']); $json_decoded = json_decode($datafromwiki, true);
if (empty($json_decoded) || !isset($json_decoded['parse'])) {
return '';
}
$datafromwiki = strval($json_decoded['parse']['text']['*']);
return self::_cleanWikidataInput($datafromwiki); return self::_cleanWikidataInput($datafromwiki);