From 1de159a2ae44b162524ec0f6ccb3dfedaccb2468 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 20 Aug 2021 03:40:23 -0400 Subject: [PATCH 1/2] Escape url tags before attempting to add missing mention links in Protocol\ActivityPub\Processor - Mastodon uses @-sign in profile URLs which wrongly triggered the mention link add in existing mentions links --- src/Protocol/ActivityPub/Processor.php | 28 +++++++++++++++----------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index 790a933bb0..47a5300352 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -1207,20 +1207,24 @@ class Processor // This prevents links to be added again to Pleroma-style mention links $body = self::normalizeMentionLinks($body); - foreach ($tags as $tag) { - if (empty($tag['name']) || empty($tag['type']) || empty($tag['href']) || !in_array($tag['type'], ['Mention', 'Hashtag'])) { - continue; + $body = BBCode::performWithEscapedTags($body, ['url'], function ($body) use ($tags) { + foreach ($tags as $tag) { + if (empty($tag['name']) || empty($tag['type']) || empty($tag['href']) || !in_array($tag['type'], ['Mention', 'Hashtag'])) { + continue; + } + + $hash = substr($tag['name'], 0, 1); + $name = substr($tag['name'], 1); + if (!in_array($hash, Tag::TAG_CHARACTER)) { + $hash = ''; + $name = $tag['name']; + } + + $body = str_replace($tag['name'], $hash . '[url=' . $tag['href'] . ']' . $name . '[/url]', $body); } - $hash = substr($tag['name'], 0, 1); - $name = substr($tag['name'], 1); - if (!in_array($hash, Tag::TAG_CHARACTER)) { - $hash = ''; - $name = $tag['name']; - } - - $body = str_replace($tag['name'], $hash . '[url=' . $tag['href'] . ']' . $name . '[/url]', $body); - } + return $body; + }); return $body; } From 940a9b2505fb6e72ded2b4285f77ecf1ed60ee10 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 20 Aug 2021 03:45:43 -0400 Subject: [PATCH 2/2] Add test for issue #10617 --- tests/src/Protocol/ActivityPub/ProcessorTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/src/Protocol/ActivityPub/ProcessorTest.php b/tests/src/Protocol/ActivityPub/ProcessorTest.php index 894e90af28..eeed1a34f2 100644 --- a/tests/src/Protocol/ActivityPub/ProcessorTest.php +++ b/tests/src/Protocol/ActivityPub/ProcessorTest.php @@ -70,6 +70,17 @@ class ProcessorTest extends TestCase ] ], ], + 'issue-10617' => [ + 'expected' => '@[url=https://mastodon.technology/@sergey_m]sergey_m[/url]', + 'body' => '@[url=https://mastodon.technology/@sergey_m]sergey_m[/url]', + 'tags' => [ + [ + 'type' => 'Mention', + 'href' => 'https://mastodon.technology/@sergey_m', + 'name' => '@sergey_m' + ], + ], + ], ]; }