From 1798e2918679ff55f1039c9a3d8150e5e52440ab Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Tue, 8 Jul 2025 17:38:34 +0200 Subject: [PATCH] Validate JSON returned from Wikidata's sparql endpoint, throw an exception if it is invalid --- src/NodaWikidataFetcher.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/NodaWikidataFetcher.php b/src/NodaWikidataFetcher.php index 3e03d71..b1f493e 100644 --- a/src/NodaWikidataFetcher.php +++ b/src/NodaWikidataFetcher.php @@ -436,6 +436,10 @@ final class NodaWikidataFetcher { $url = 'https://query.wikidata.org/sparql?query=' . urlencode($sparqlQuery); $result = MD_STD::runCurl($url, 100000000, self::WIKIDATA_FETCH_HEADERS); + if (json_validate($result) === false) { + throw new MDhttpFailedException("Failed to run SPARQL query"); + } + return json_decode($result, true); }