From a2269f57453401c08593ca2683354a6aabc2da78 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Fri, 14 Aug 2020 00:19:26 +0000 Subject: [PATCH] [UTIL][Common] Implement 'isSystemPath' --- src/Util/Common.php | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/Util/Common.php b/src/Util/Common.php index 5f9b8de19a..bf321d3a24 100644 --- a/src/Util/Common.php +++ b/src/Util/Common.php @@ -37,6 +37,7 @@ use App\Core\Router; use App\Core\Security; use App\Entity\GSActor; use App\Entity\LocalUser; +use Exception; use Functional as F; abstract class Common @@ -87,32 +88,12 @@ abstract class Common */ public static function isSystemPath(string $str): bool { - // TODO Implement - return false; - - // $paths = []; - - // // All directory and file names in site root should be blacklisted - // $d = dir(PUBLICDIR); - // while (false !== ($entry = $d->read())) { - // $paths[$entry] = true; - // } - // $d->close(); - - // // All top level names in the router should be blocked - // $router = Router::get(); - // foreach ($router->m->getPaths() as $path) { - // if (preg_match('/^([^\/\?]+)[\/\?]/', $path, $matches) && isset($matches[1])) { - // $paths[$matches[1]] = true; - // } - // } - - // // FIXME: this assumes the 'path' is in the first-level directory, though common it's not certain - // foreach (['avatar', 'attachments'] as $cat) { - // $paths[basename(common_config($cat, 'path'))] = true; - // } - - // return in_arry($str, array_keys($paths)); + try { + Router::match('/' . $str); + return true; + } catch (Exception $e) { + return false; + } } /**