diff --git a/lib/AbstractException.php b/lib/AbstractException.php index 1e3a2dd3..0165d464 100644 --- a/lib/AbstractException.php +++ b/lib/AbstractException.php @@ -94,6 +94,7 @@ abstract class AbstractException extends \Exception { "ImportExport/Exception.invalidSemantics" => 10612, "ImportExport/Exception.invalidFolderName" => 10613, "ImportExport/Exception.invalidFolderCopy" => 10614, + "ImportExport/Exception.invalidTagName" => 10615, ]; public function __construct(string $msgID = "", $vars = null, \Throwable $e = null) { diff --git a/lib/ImportExport/AbstractImportExport.php b/lib/ImportExport/AbstractImportExport.php index 3a234438..66cc9b23 100644 --- a/lib/ImportExport/AbstractImportExport.php +++ b/lib/ImportExport/AbstractImportExport.php @@ -85,8 +85,8 @@ abstract class AbstractImportExport { // compile the set of used tags, if this is a new feed or we're doing a full replacement foreach ($f['tags'] as $t) { if (!strlen(trim($t))) { - // ignore any blank tags - continue; + // fail if we have any blank tags + throw new Exception("invalidTagName"); } if (!isset($tagMap[$t])) { // populate the tag map diff --git a/lib/ImportExport/OPML.php b/lib/ImportExport/OPML.php index aa311f8a..30a3cc51 100644 --- a/lib/ImportExport/OPML.php +++ b/lib/ImportExport/OPML.php @@ -61,6 +61,10 @@ class OPML extends AbstractImportExport { $categories = array_map(function($v) { return trim(preg_replace("/\s+/", " ", $v)); }, explode(",", $categories)); + // filter out any blank categories + $categories = array_filter($categories, function($v) { + return strlen($v); + }); } else { $categories = []; } diff --git a/locale/en.php b/locale/en.php index 19fc7241..e095db8a 100644 --- a/locale/en.php +++ b/locale/en.php @@ -163,4 +163,5 @@ return [ 'Exception.JKingWeb/Arsse/ImportExport/Exception.invalidSemantics' => 'Input data is not valid {type} data', 'Exception.JKingWeb/Arsse/ImportExport/Exception.invalidFolderName' => 'Input data contains an invalid folder name', 'Exception.JKingWeb/Arsse/ImportExport/Exception.invalidFolderCopy' => 'Input data contains multiple folders of the same name under the same parent', + 'Exception.JKingWeb/Arsse/ImportExport/Exception.invalidTagName' => 'Input data contains an invalid tag name', ]; diff --git a/tests/cases/ImportExport/TestOPML.php b/tests/cases/ImportExport/TestOPML.php index e4ef7b42..503211ca 100644 --- a/tests/cases/ImportExport/TestOPML.php +++ b/tests/cases/ImportExport/TestOPML.php @@ -135,7 +135,7 @@ OPML_EXPORT_SERIALIZATION; ['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", ""]], + ['url' => "", 'title' => "", 'folder' => 0, 'tags' => ["whee", "whoo"]], ], []]], ["FoldersOnly.opml", true, [[], []]], ["FoldersOnly.opml", false, [[], [1 =>