diff options
Diffstat (limited to 'app/Models/Feed.php')
| -rw-r--r-- | app/Models/Feed.php | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/app/Models/Feed.php b/app/Models/Feed.php index 57bf9d7a4..072948e1b 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -725,8 +725,25 @@ class FreshRSS_Feed extends Minz_Model { } $xpath = new DOMXPath($doc); - $json = @$xpath->evaluate('normalize-space(' . $xPathToJson . ')'); - return is_string($json) ? $json : null; + $jsonFragments = @$xpath->evaluate($xPathToJson); + if ($jsonFragments === false) { + return null; + } + if (is_string($jsonFragments)) { + return $jsonFragments; + } + if ($jsonFragments instanceof DOMNodeList && $jsonFragments->length > 0) { + // If the result is a list, then aggregate as a JSON array + $result = []; + foreach ($jsonFragments as $node) { + $json = json_decode($node->textContent, true); + if (json_last_error() === JSON_ERROR_NONE && is_array($json)) { + $result[] = $json; + } + } + return json_encode($result, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) ?: null; + } + return null; } public function loadJson(): ?\SimplePie\SimplePie { |
