mirror of
https://git.sekbaer.de/Friendica/friendica.git
synced 2025-06-12 01:54:26 +02:00
Refine BBCode::expandTags regular expression
- Now requires the tag to be preceded by either a non-word character or a start of a line - Added corresponding tests
This commit is contained in:
parent
5a93bb6eff
commit
8e99b7f775
2 changed files with 31 additions and 2 deletions
|
@ -2289,14 +2289,14 @@ class BBCode
|
|||
}
|
||||
|
||||
/**
|
||||
* Expand tags to URLs
|
||||
* Expand tags to URLs, checks the tag is at the start of a line or preceded by a non-word character
|
||||
*
|
||||
* @param string $body
|
||||
* @return string body with expanded tags
|
||||
*/
|
||||
public static function expandTags(string $body)
|
||||
{
|
||||
return preg_replace_callback("/([!#@])([^\^ \x0D\x0A,;:?\']*[^\^ \x0D\x0A,;:?!\'.])/",
|
||||
return preg_replace_callback("/(?<=\W|^)([!#@])([^\^ \x0D\x0A,;:?'\"]*[^\^ \x0D\x0A,;:?!'\".])/",
|
||||
function ($match) {
|
||||
switch ($match[1]) {
|
||||
case '!':
|
||||
|
@ -2309,6 +2309,7 @@ class BBCode
|
|||
}
|
||||
break;
|
||||
case '#':
|
||||
default:
|
||||
return $match[1] . '[url=' . 'https://' . DI::baseUrl() . '/search?tag=' . $match[2] . ']' . $match[2] . '[/url]';
|
||||
}
|
||||
}, $body);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue