diff --git a/lib/nickname.php b/lib/nickname.php index 6e638c21b7..e21517497a 100644 --- a/lib/nickname.php +++ b/lib/nickname.php @@ -54,7 +54,10 @@ class Nickname * We could probably use an email regex here, but mainly we are interested * in matching it in our URLs, like https://social.example/user@example.com */ - const WEBFINGER_FMT = '[0-9a-zA-Z_]{1,64}\@[0-9a-zA-Z_-.]{3,255}'; + const WEBFINGER_FMT = '(?:\w+[\w\-\_\.]*)?\w+\@'.URL_REGEX_DOMAIN_NAME; + + // old one without support for -_. in nickname part: + // const WEBFINGER_FMT = '[0-9a-zA-Z_]{1,64}\@[0-9a-zA-Z_-.]{3,255}'; /** * Regex fragment for checking a canonical nickname. diff --git a/lib/util.php b/lib/util.php index d1d79d1282..07773a06f3 100644 --- a/lib/util.php +++ b/lib/util.php @@ -768,7 +768,7 @@ function common_find_mentions($text, Profile $sender, Notice $parent=null) } } - $matches = common_find_mentions_raw($text); + $matches = common_find_mentions_raw($text, '@'); foreach ($matches as $match) { try { @@ -879,9 +879,10 @@ function common_find_mentions($text, Profile $sender, Notice $parent=null) * Should generally not be called directly; for use in common_find_mentions. * * @param string $text + * @param string $preMention Character(s) that signals a mention ('@', '!'...) * @return array of PCRE match arrays */ -function common_find_mentions_raw($text) +function common_find_mentions_raw($text, $preMention='@') { $tmatches = array(); preg_match_all('/^T (' . Nickname::DISPLAY_FMT . ') /', @@ -891,7 +892,7 @@ function common_find_mentions_raw($text) $atmatches = array(); // the regexp's "(?!\@)" makes sure it doesn't matches the single "@remote" in "@remote@server.com" - preg_match_all('/'.Nickname::BEFORE_MENTIONS.'@(' . Nickname::DISPLAY_FMT . ')\b(?!\@)/', + preg_match_all('/'.Nickname::BEFORE_MENTIONS.preg_quote($preMention, '/').'(' . Nickname::DISPLAY_FMT . ')\b(?!\@)/', $text, $atmatches, PREG_OFFSET_CAPTURE); diff --git a/plugins/OStatus/OStatusPlugin.php b/plugins/OStatus/OStatusPlugin.php index 7f7f04c50a..6f70d65ab2 100644 --- a/plugins/OStatus/OStatusPlugin.php +++ b/plugins/OStatus/OStatusPlugin.php @@ -258,14 +258,16 @@ class OStatusPlugin extends Plugin /** * Webfinger matches: @user@example.com or even @user--one.george_orwell@1984.biz + * @param string $text The text from which to extract webfinger IDs + * @param string $preMention Character(s) that signals a mention ('@', '!'...) * * @return array The matching IDs (without @ or acct:) and each respective position in the given string. */ - static function extractWebfingerIds($text) + static function extractWebfingerIds($text, $preMention='@') { $wmatches = array(); // Maybe this should harmonize with lib/nickname.php and Nickname::WEBFINGER_FMT - $result = preg_match_all('/(?log(LOG_INFO, "Checking webfinger '$target'"); $profile = null;