X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FContent%2FPageInfo.php;h=e4d9207c8c43eaaf7b066978e52b865439d9b7c1;hb=018abb4d1dfbe0bf29b441dce281d89a437075b4;hp=212082f9f3664e26ff53fa87d92bb7ad15c2b7fb;hpb=972b65ba33f65be3fee4b6201304702c51b22ed3;p=friendica.git diff --git a/src/Content/PageInfo.php b/src/Content/PageInfo.php index 212082f9f3..e4d9207c8c 100644 --- a/src/Content/PageInfo.php +++ b/src/Content/PageInfo.php @@ -272,22 +272,35 @@ class PageInfo /** * Remove the provided URL from the body if it is at the end of it. - * Keep the link label if it isn't the full URL. + * Keep the link label if it isn't the full URL or a shortened version of it. * * @param string $body * @param string $url - * @return string|string[]|null + * @return string */ protected static function stripTrailingUrlFromBody(string $body, string $url) { $quotedUrl = preg_quote($url, '#'); - $body = preg_replace("#(?: + $body = preg_replace_callback("#(?: \[url]$quotedUrl\[/url]| \[url=$quotedUrl]$quotedUrl\[/url]| \[url=$quotedUrl]([^[]*?)\[/url]| $quotedUrl - )$#isx", '$1', $body); + )$#isx", function ($match) use ($url) { + // Stripping URLs with no label + if (!isset($match[1])) { + return ''; + } - return $body; + // Stripping link labels that include a shortened version of the URL + if (strpos($url, trim($match[1], '.…')) !== false) { + return ''; + } + + // Keep all other labels + return $match[1]; + }, $body); + + return rtrim($body); } }