diff --git a/lib/ImportExport/OPML.php b/lib/ImportExport/OPML.php index b8711bdd..ca02f2d4 100644 --- a/lib/ImportExport/OPML.php +++ b/lib/ImportExport/OPML.php @@ -145,8 +145,8 @@ class OPML { $err = libxml_get_last_error(); throw new Exception("invalidSyntax", ['line' => $err->line, 'column' => $err->column]); } - $body = $d->getElementsByTagName("body"); - if ($d->documentElement->nodeName !== "opml" || !$body->length || !$body->item(0)->parentNode->isSameNode($d->documentElement)) { + $body = (new \DOMXPath($d))->query("/opml/body"); + if ($body->length != 1) { // not a valid OPML document throw new Exception("invalidSemantics", ['type' => "OPML"]); } diff --git a/tests/cases/ImportExport/TestOPML.php b/tests/cases/ImportExport/TestOPML.php index a17cdaff..33904447 100644 --- a/tests/cases/ImportExport/TestOPML.php +++ b/tests/cases/ImportExport/TestOPML.php @@ -114,7 +114,7 @@ OPML_EXPORT_SERIALIZATION; $this->assertException($exp); $parser->parse($data, $flat); } else { - $this->assertSame($exp, $parse->parse($data, $flat)); + $this->assertSame($exp, $parser->parse($data, $flat)); } } @@ -124,6 +124,10 @@ OPML_EXPORT_SERIALIZATION; ["BrokenOPML.1.opml", false, new Exception("invalidSemantics")], ["BrokenOPML.2.opml", false, new Exception("invalidSemantics")], ["BrokenOPML.3.opml", false, new Exception("invalidSemantics")], + ["BrokenOPML.4.opml", false, new Exception("invalidSemantics")], + ["Empty.1.opml", false, [[], []]], + ["Empty.2.opml", false, [[], []]], + ["Empty.3.opml", false, [[], []]], ]; } } diff --git a/tests/docroot/Import/OPML/BrokenOPML.1.opml b/tests/docroot/Import/OPML/BrokenOPML.1.opml index 1f551eab..a626ae06 100644 --- a/tests/docroot/Import/OPML/BrokenOPML.1.opml +++ b/tests/docroot/Import/OPML/BrokenOPML.1.opml @@ -1 +1,2 @@ + diff --git a/tests/docroot/Import/OPML/BrokenOPML.2.opml b/tests/docroot/Import/OPML/BrokenOPML.2.opml index a6c08015..ac70153f 100644 --- a/tests/docroot/Import/OPML/BrokenOPML.2.opml +++ b/tests/docroot/Import/OPML/BrokenOPML.2.opml @@ -1 +1,2 @@ + diff --git a/tests/docroot/Import/OPML/BrokenOPML.3.opml b/tests/docroot/Import/OPML/BrokenOPML.3.opml index 466ca0ca..b087a1b6 100644 --- a/tests/docroot/Import/OPML/BrokenOPML.3.opml +++ b/tests/docroot/Import/OPML/BrokenOPML.3.opml @@ -3,3 +3,4 @@ + diff --git a/tests/docroot/Import/OPML/BrokenOPML.4.opml b/tests/docroot/Import/OPML/BrokenOPML.4.opml new file mode 100644 index 00000000..544e4c36 --- /dev/null +++ b/tests/docroot/Import/OPML/BrokenOPML.4.opml @@ -0,0 +1,5 @@ + + + + + diff --git a/tests/docroot/Import/OPML/BrokenXML.opml b/tests/docroot/Import/OPML/BrokenXML.opml index 95028ac2..0cbc6fe2 100644 --- a/tests/docroot/Import/OPML/BrokenXML.opml +++ b/tests/docroot/Import/OPML/BrokenXML.opml @@ -1 +1,2 @@ + diff --git a/tests/docroot/Import/OPML/Empty.1.opml b/tests/docroot/Import/OPML/Empty.1.opml new file mode 100644 index 00000000..4999faaf --- /dev/null +++ b/tests/docroot/Import/OPML/Empty.1.opml @@ -0,0 +1,4 @@ + + + + diff --git a/tests/docroot/Import/OPML/Empty.2.opml b/tests/docroot/Import/OPML/Empty.2.opml new file mode 100644 index 00000000..6dcd03f2 --- /dev/null +++ b/tests/docroot/Import/OPML/Empty.2.opml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/tests/docroot/Import/OPML/Empty.3.opml b/tests/docroot/Import/OPML/Empty.3.opml new file mode 100644 index 00000000..59fd9b46 --- /dev/null +++ b/tests/docroot/Import/OPML/Empty.3.opml @@ -0,0 +1,11 @@ + + + + + + + + + + +