Fix wrongly linkified image urls with markdown AP content

When we get a Markdown source in AP, we prefer that over HTML. Our linkifying of urls however should not be run in this case, we want the markdown to be as it was sent.

Fixes broken images between Socialhome instances.
fix-images
Jason Robinson 2020-12-27 22:59:21 +02:00
rodzic e55f13a117
commit 33c6edac7f
2 zmienionych plików z 15 dodań i 0 usunięć

Wyświetl plik

@ -67,6 +67,10 @@ class CleanContentMixin(RawContentMixin):
return
return attrs
if self._media_type == "text/markdown":
# Skip when markdown
return
self.raw_content = bleach.linkify(
self.raw_content,
callbacks=[remove_tag_links],

Wyświetl plik

@ -481,6 +481,17 @@ class TestEntitiesPostReceive:
"public": False,
}]
@patch("federation.entities.activitypub.entities.bleach.linkify", autospec=True)
def test_post_post_receive__linkifies_if_not_markdown(self, mock_linkify, activitypubpost):
activitypubpost._media_type = 'text/html'
activitypubpost.post_receive()
mock_linkify.assert_called_once()
@patch("federation.entities.activitypub.entities.bleach.linkify", autospec=True)
def test_post_post_receive__skips_linkify_if_markdown(self, mock_linkify, activitypubpost):
activitypubpost.post_receive()
mock_linkify.assert_not_called()
class TestEntitiesPreSend:
def test_post_inline_images_are_attached(self, activitypubpost_embedded_images):