Fix international domains

This commit is contained in:
Michael 2024-05-20 09:11:09 +00:00
parent 97c12055a2
commit 7176fed316

View file

@ -48,6 +48,7 @@ use Friendica\Util\ParseUrl;
use Friendica\Util\Proxy; use Friendica\Util\Proxy;
use Friendica\Util\Strings; use Friendica\Util\Strings;
use Friendica\Util\XML; use Friendica\Util\XML;
use GuzzleHttp\Psr7\Uri;
class BBCode class BBCode
{ {
@ -147,7 +148,7 @@ class BBCode
case 'title': case 'title':
$value = self::toPlaintext(html_entity_decode($value, ENT_QUOTES, 'UTF-8')); $value = self::toPlaintext(html_entity_decode($value, ENT_QUOTES, 'UTF-8'));
$value = html_entity_decode($value, ENT_QUOTES, 'UTF-8'); $value = html_entity_decode($value, ENT_QUOTES, 'UTF-8');
$data['title'] = self::escapeUrl($value); $data['title'] = self::escapeContent($value);
default: default:
$data[$field] = html_entity_decode($value, ENT_QUOTES, 'UTF-8'); $data[$field] = html_entity_decode($value, ENT_QUOTES, 'UTF-8');
@ -312,6 +313,7 @@ class BBCode
public static function proxyUrl(string $image, int $simplehtml = self::INTERNAL, int $uriid = 0, string $size = ''): string public static function proxyUrl(string $image, int $simplehtml = self::INTERNAL, int $uriid = 0, string $size = ''): string
{ {
$image = self::idnUrl($image);
// Only send proxied pictures to API and for internal display // Only send proxied pictures to API and for internal display
if (!in_array($simplehtml, [self::INTERNAL, self::MASTODON_API, self::TWITTER_API])) { if (!in_array($simplehtml, [self::INTERNAL, self::MASTODON_API, self::TWITTER_API])) {
return $image; return $image;
@ -2105,10 +2107,26 @@ class BBCode
} }
private static function escapeUrl(string $url): string private static function escapeUrl(string $url): string
{
return self::escapeContent(self::idnUrl($url));
}
private static function escapeContent(string $url): string
{ {
return str_replace(['[', ']'], ['[', ']'], $url); return str_replace(['[', ']'], ['[', ']'], $url);
} }
private static function idnUrl(string $url): string
{
$parts = parse_url($url);
if (empty($parts)) {
return $url;
}
$parts['host'] = idn_to_ascii(urldecode($parts['host']));
return (string)Uri::fromParts($parts);
}
private static function unifyLinks(string $text): string private static function unifyLinks(string $text): string
{ {
return preg_replace_callback( return preg_replace_callback(