Merge pull request #10618 from MrPetovan/task/10603-ap-string-mentions
Escape url tags before attempting to add missing mention links in Protocol\ActivityPub\Processor
This commit is contained in:
commit
1d5427aca8
2 changed files with 27 additions and 12 deletions
|
@ -1207,20 +1207,24 @@ class Processor
|
||||||
// This prevents links to be added again to Pleroma-style mention links
|
// This prevents links to be added again to Pleroma-style mention links
|
||||||
$body = self::normalizeMentionLinks($body);
|
$body = self::normalizeMentionLinks($body);
|
||||||
|
|
||||||
foreach ($tags as $tag) {
|
$body = BBCode::performWithEscapedTags($body, ['url'], function ($body) use ($tags) {
|
||||||
if (empty($tag['name']) || empty($tag['type']) || empty($tag['href']) || !in_array($tag['type'], ['Mention', 'Hashtag'])) {
|
foreach ($tags as $tag) {
|
||||||
continue;
|
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);
|
return $body;
|
||||||
$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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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'
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue