Browse Source

Tests and fixed for OPML feed parsing

microsub
J. King 5 years ago
parent
commit
a30114807f
  1. 4
      lib/ImportExport/OPML.php
  2. 38
      tests/cases/ImportExport/TestOPML.php
  3. 12
      tests/docroot/Import/OPML/FeedsOnly.opml

4
lib/ImportExport/OPML.php

@ -158,7 +158,7 @@ class OPML {
$folderMap[$body] = sizeof($folderMap);
// iterate through each node in the body
$node = $body->firstChild;
while ($node && $node != $body) {
while ($node && !$node->isSameNode($body)) {
if ($node->nodeType == \XML_ELEMENT_NODE && $node->nodeName === "outline") {
// process any nodes which are outlines
if ($node->getAttribute("type") === "rss") {
@ -170,7 +170,7 @@ class OPML {
if (strlen($categories)) {
// collapse and trim whitespace from category names, if any, splitting along commas
$categories = array_map(function($v) {
return trim(preg_replace("/\s+/g", " ", $v));
return trim(preg_replace("/\s+/", " ", $v));
}, explode(",", $categories));
} else {
$categories = [];

38
tests/cases/ImportExport/TestOPML.php

@ -128,6 +128,44 @@ OPML_EXPORT_SERIALIZATION;
["Empty.1.opml", false, [[], []]],
["Empty.2.opml", false, [[], []]],
["Empty.3.opml", false, [[], []]],
["FeedsOnly.opml", false, [[
[
'url' => "http://example.com/1",
'title' => "Feed 1",
'folder' => 0,
'tags' => [],
],
[
'url' => "http://example.com/2",
'title' => "",
'folder' => 0,
'tags' => [],
],
[
'url' => "http://example.com/3",
'title' => "",
'folder' => 0,
'tags' => [],
],
[
'url' => "http://example.com/4",
'title' => "",
'folder' => 0,
'tags' => [],
],
[
'url' => "",
'title' => "",
'folder' => 0,
'tags' => ["whee"],
],
[
'url' => "",
'title' => "",
'folder' => 0,
'tags' => ["whee", "whoo", ""],
],
], []]],
];
}
}

12
tests/docroot/Import/OPML/FeedsOnly.opml

@ -0,0 +1,12 @@
<opml>
<body>
<outline type="rss" xmlUrl="http://example.com/1" text="Feed 1"/>
<outline type="rss" xmlUrl="http://example.com/2" text=""/>
<outline type="rss" xmlUrl="http://example.com/3"/>
<outline type="rss" xmlUrl="http://example.com/4" title="Feed 4"> <!-- Only the "text" attribute is used -->
<outline type="rss" xmlUrl="http://example.com/!" title="Not a feed"/> <!-- Any descendants of a feed are skipped -->
</outline>
<outline type="rss" xmlUrl="" category="whee"/>
<outline type="rss" category="whee,whoo,"/>
</body>
</opml>
Loading…
Cancel
Save