From 0c472402f22816daa66982a815febc464c4856c8 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Fri, 9 Sep 2022 22:56:34 +0200 Subject: Workaround invalid OPMLs (#4591) * Workaround invalid OPMLs #fix https://github.com/FreshRSS/FreshRSS/issues/4590 Accept OPML files lacking text attributes * Tolerate missing head element --- lib/lib_opml.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'lib/lib_opml.php') diff --git a/lib/lib_opml.php b/lib/lib_opml.php index 86847d720..f86d780b7 100644 --- a/lib/lib_opml.php +++ b/lib/lib_opml.php @@ -189,16 +189,17 @@ function libopml_parse_string($xml, $strict = true) { 'body' => array() ); - // First, we get all "head" elements. Head is required but its sub-elements - // are optional. - foreach ($opml->head->children() as $key => $value) { - if (in_array($key, unserialize(HEAD_ELEMENTS), true)) { - $array['head'][$key] = (string)$value; - } elseif ($strict) { - throw new LibOPML_Exception( - $key . ' is not part of the OPML 2.0 specification' - ); + if (isset($opml->head)) { + // We get all "head" elements. Head is required but its sub-elements are optional. + foreach ($opml->head->children() as $key => $value) { + if (in_array($key, unserialize(HEAD_ELEMENTS), true)) { + $array['head'][$key] = (string)$value; + } elseif ($strict) { + throw new LibOPML_Exception($key . ' is not part of the OPML 2.0 specification'); + } } + } elseif ($strict) { + throw new LibOPML_Exception('Required OPML head element is missing!'); } // Then, we get body oulines. Body must contain at least one outline -- cgit v1.2.3