X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fnickname.php;h=6e638c21b74039a3316532271493b060af5dab68;hb=dd8e17a3874aa99063b62b51e9a637a5abb0b923;hp=1ed0abbe78dbfcec46365c97f73684cb2ff34b83;hpb=8ad81a6aa32e69257d3402200910600ed6616360;p=quix0rs-gnu-social.git diff --git a/lib/nickname.php b/lib/nickname.php index 1ed0abbe78..6e638c21b7 100644 --- a/lib/nickname.php +++ b/lib/nickname.php @@ -76,6 +76,16 @@ class Nickname */ const MAX_LEN = 64; + /** + * Regex with non-capturing group that matches whitespace and some + * characters which are allowed right before an @ or ! when mentioning + * other users. Like: 'This goes out to:@mmn (@chimo too) (!awwyiss).' + * + * FIXME: Make this so you can have multiple whitespace but not multiple + * parenthesis or something. '(((@n_n@)))' might as well be a smiley. + */ + const BEFORE_MENTIONS = '(?:^|[\s\.\,\:\;\[\(]+)'; + /** * Nice simple check of whether the given string is a valid input nickname, * which can be normalized into an internally canonical form. @@ -116,15 +126,17 @@ class Nickname */ public static function normalize($str, $checkuse=false) { + if (mb_strlen($str) > self::MAX_LEN) { + // Display forms must also fit! + throw new NicknameTooLongException(); + } + // We should also have UTF-8 normalization (Ã¥ to a etc.) $str = trim($str); $str = str_replace('_', '', $str); $str = mb_strtolower($str); - if (mb_strlen($str) > self::MAX_LEN) { - // Display forms must also fit! - throw new NicknameTooLongException(); - } elseif (mb_strlen($str) < 1) { + if (mb_strlen($str) < 1) { throw new NicknameEmptyException(); } elseif (!self::isCanonical($str)) { throw new NicknameInvalidException(); @@ -162,6 +174,8 @@ class Nickname public static function isBlacklisted($str) { $blacklist = common_config('nickname', 'blacklist'); + if(!$blacklist) + return false; return in_array($str, $blacklist); } @@ -180,18 +194,24 @@ class Nickname // All directory and file names in site root should be blacklisted $d = dir(INSTALLDIR); while (false !== ($entry = $d->read())) { - $paths[] = $entry; + $paths[$entry] = true; } $d->close(); // All top level names in the router should be blacklisted $router = Router::get(); - foreach (array_keys($router->m->getPaths()) as $path) { - if (preg_match('/^\/(.*?)[\/\?]/',$path,$matches)) { - $paths[] = $matches[1]; + foreach ($router->m->getPaths() as $path) { + if (preg_match('/^([^\/\?]+)[\/\?]/',$path,$matches) && isset($matches[1])) { + $paths[$matches[1]] = true; } } - return in_array($str, $paths); + + // 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_array($str, array_keys($paths)); } /**