kopia lustrzana https://github.com/friendica/friendica
Porównaj commity
1 Commity
45b30825f0
...
bd10441409
Autor | SHA1 | Data |
---|---|---|
Michael | bd10441409 |
|
@ -51,7 +51,7 @@ use Friendica\Util\XML;
|
|||
class BBCode
|
||||
{
|
||||
// Update this value to the current date whenever changes are made to BBCode::convert
|
||||
const VERSION = '2021-07-28';
|
||||
const VERSION = '2024-04-07';
|
||||
|
||||
const INTERNAL = 0;
|
||||
const EXTERNAL = 1;
|
||||
|
@ -1988,6 +1988,10 @@ class BBCode
|
|||
return $text;
|
||||
});
|
||||
|
||||
if (!$for_plaintext && in_array($simple_html, [self::INTERNAL, self::EXTERNAL, self::DIASPORA])) {
|
||||
$text = self::shortenLinkDescription($text);
|
||||
}
|
||||
|
||||
// We need no target="_blank" rel="noopener noreferrer" for local links
|
||||
// convert links start with DI::baseUrl() as local link without the target="_blank" rel="noopener noreferrer" attribute
|
||||
$escapedBaseUrl = preg_quote(DI::baseUrl(), '/');
|
||||
|
@ -2112,6 +2116,31 @@ class BBCode
|
|||
return trim($text);
|
||||
}
|
||||
|
||||
private static function shortenLinkDescription(string $text): string
|
||||
{
|
||||
$text = preg_replace_callback(
|
||||
"/\[url\](.*?)\[\/url\]/ism",
|
||||
function ($match) {
|
||||
$url = str_replace(['[', ']'], ['[', ']'], $match[1]);
|
||||
return "[url=" . $url . "]" . Strings::getStyledURL($match[1]) . "[/url]";
|
||||
},
|
||||
$text
|
||||
);
|
||||
$text = preg_replace_callback(
|
||||
"/\[url\=(.*?)\](.*?)\[\/url\]/ism",
|
||||
function ($match) {
|
||||
$url = str_replace(['[', ']'], ['[', ']'], $match[1]);
|
||||
if ($match[1] == $match[2]) {
|
||||
return "[url=" . $url . "]" . Strings::getStyledURL($match[2]) . "[/url]";
|
||||
} else {
|
||||
return "[url=" . $url . "]" . $match[2] . "[/url]";
|
||||
}
|
||||
},
|
||||
$text
|
||||
);
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips the "abstract" tag from the provided text
|
||||
*
|
||||
|
|
|
@ -569,6 +569,10 @@ class Strings
|
|||
public static function getStyledURL(string $url): string
|
||||
{
|
||||
$parts = parse_url($url);
|
||||
if (empty($parts['scheme'])) {
|
||||
return $url;
|
||||
}
|
||||
|
||||
$scheme = [$parts['scheme'] . '://www.', $parts['scheme'] . '://'];
|
||||
$styled_url = str_replace($scheme, '', $url);
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ use Friendica\Content\Text\BBCode;
|
|||
use Friendica\DI;
|
||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||
use Friendica\Test\FixtureTest;
|
||||
use Friendica\Util\Strings;
|
||||
|
||||
class BBCodeTest extends FixtureTest
|
||||
{
|
||||
|
@ -148,7 +149,7 @@ class BBCodeTest extends FixtureTest
|
|||
public function testAutoLinking(string $data, bool $assertHTML)
|
||||
{
|
||||
$output = BBCode::convert($data);
|
||||
$assert = $this->HTMLPurifier->purify('<a href="' . $data . '" target="_blank" rel="noopener noreferrer">' . $data . '</a>');
|
||||
$assert = $this->HTMLPurifier->purify('<a href="' . $data . '" target="_blank" rel="noopener noreferrer">' . Strings::getStyledURL($data) . '</a>');
|
||||
if ($assertHTML) {
|
||||
self::assertEquals($assert, $output);
|
||||
} else {
|
||||
|
@ -160,21 +161,21 @@ class BBCodeTest extends FixtureTest
|
|||
{
|
||||
return [
|
||||
'bug-7271-condensed-space' => [
|
||||
'expectedHtml' => '<ol><li> <a href="http://example.com/" target="_blank" rel="noopener noreferrer">http://example.com/</a></li></ol>',
|
||||
'expectedHtml' => '<ol><li> <a href="http://example.com/" target="_blank" rel="noopener noreferrer">example.com/</a></li></ol>',
|
||||
'text' => '[ol][li] http://example.com/[/ol]',
|
||||
],
|
||||
'bug-7271-condensed-nospace' => [
|
||||
'expectedHtml' => '<ol><li><a href="http://example.com/" target="_blank" rel="noopener noreferrer">http://example.com/</a></li></ol>',
|
||||
'expectedHtml' => '<ol><li><a href="http://example.com/" target="_blank" rel="noopener noreferrer">example.com/</a></li></ol>',
|
||||
'text' => '[ol][li]http://example.com/[/ol]',
|
||||
],
|
||||
'bug-7271-indented-space' => [
|
||||
'expectedHtml' => '<ul><li> <a href="http://example.com/" target="_blank" rel="noopener noreferrer">http://example.com/</a></li></ul>',
|
||||
'expectedHtml' => '<ul><li> <a href="http://example.com/" target="_blank" rel="noopener noreferrer">example.com/</a></li></ul>',
|
||||
'text' => '[ul]
|
||||
[li] http://example.com/
|
||||
[/ul]',
|
||||
],
|
||||
'bug-7271-indented-nospace' => [
|
||||
'expectedHtml' => '<ul><li><a href="http://example.com/" target="_blank" rel="noopener noreferrer">http://example.com/</a></li></ul>',
|
||||
'expectedHtml' => '<ul><li><a href="http://example.com/" target="_blank" rel="noopener noreferrer">example.com/</a></li></ul>',
|
||||
'text' => '[ul]
|
||||
[li]http://example.com/
|
||||
[/ul]',
|
||||
|
|
Ładowanie…
Reference in New Issue