X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2FLinkFilter.php;h=e693b28428ba3951d2a6898b75941e0c5bd50572;hb=bb9ca54838e2f877635197541e8439171c83d5dc;hp=3fd803cb81f4d79c08538a8fc3a7079d8f0b9644;hpb=c51fae92dc7d3080def81a2797e0d683b3e6d82a;p=github%2Fshaarli%2FShaarli.git diff --git a/application/LinkFilter.php b/application/LinkFilter.php index 3fd803cb..e693b284 100644 --- a/application/LinkFilter.php +++ b/application/LinkFilter.php @@ -44,7 +44,7 @@ class LinkFilter * Filter links according to parameters. * * @param string $type Type of filter (eg. tags, permalink, etc.). - * @param string $request Filter content. + * @param mixed $request Filter content. * @param bool $casesensitive Optional: Perform case sensitive filter if true. * @param bool $privateonly Optional: Only returns private links if true. * @@ -110,6 +110,8 @@ class LinkFilter * @param string $smallHash permalink hash. * * @return array $filtered array containing permalink data. + * + * @throws LinkNotFoundException if the smallhash doesn't match any link. */ private function filterSmallHash($smallHash) { @@ -121,6 +123,11 @@ class LinkFilter return $filtered; } } + + if (empty($filtered)) { + throw new LinkNotFoundException(); + } + return $filtered; } @@ -315,6 +322,11 @@ class LinkFilter $tagsOut = $casesensitive ? $tags : mb_convert_case($tags, MB_CASE_LOWER, 'UTF-8'); $tagsOut = str_replace(',', ' ', $tagsOut); - return array_filter(explode(' ', trim($tagsOut)), 'strlen'); + return array_values(array_filter(explode(' ', trim($tagsOut)), 'strlen')); } } + +class LinkNotFoundException extends Exception +{ + protected $message = 'The link you are trying to reach does not exist or has been deleted.'; +}