Skip to content

Commit

Permalink
Fix hashtag being handled as common link in the preview card (jointak…
Browse files Browse the repository at this point in the history
  • Loading branch information
humrochagf authored Feb 20, 2023
1 parent 1f3f28e commit e625fae
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
4 changes: 2 additions & 2 deletions core/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ def create_hashtag(self, hashtag) -> str:
hashtag = hashtag.lstrip("#")
self.hashtags.add(hashtag.lower())
if self.uri_domain:
return f'<a href="https://{self.uri_domain}/tags/{hashtag.lower()}/">#{hashtag}</a>'
return f'<a href="https://{self.uri_domain}/tags/{hashtag.lower()}/" rel="tag">#{hashtag}</a>'
else:
return f'<a href="/tags/{hashtag.lower()}/">#{hashtag}</a>'
return f'<a href="/tags/{hashtag.lower()}/" rel="tag">#{hashtag}</a>'

def create_emoji(self, shortcode) -> str:
"""
Expand Down
20 changes: 20 additions & 0 deletions tests/activities/models/test_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,23 @@ def test_inbound_posts(
# Run stator and ensure that deleted the post
stator.run_single_cycle_sync()
assert not Post.objects.filter(object_uri="https://remote.test/test-post").exists()


@pytest.mark.django_db
def test_post_hashtag_to_ap(identity: Identity, config_system):
"""
Tests post hashtags conversion to AP format.
"""
post = Post.create_local(author=identity, content="Hello #world")
assert post.hashtags == ["world"]

ap = post.to_create_ap()
assert ap["object"]["tag"] == [
{
"href": "https://example.com/tags/world/",
"name": "#world",
"type": "Hashtag",
}
]
assert "#world" in ap["object"]["content"]
assert 'rel="tag"' in ap["object"]["content"]
2 changes: 1 addition & 1 deletion tests/core/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def test_parser(identity):
)
assert (
parser.html
== '<a href="http://example.com#notahashtag" rel="nofollow">something</a> <a href="/tags/hashtag/">#hashtag</a> <a href="/tags/hashtagtwo/">#hashtagtwo</a>'
== '<a href="http://example.com#notahashtag" rel="nofollow">something</a> <a href="/tags/hashtag/" rel="tag">#hashtag</a> <a href="/tags/hashtagtwo/" rel="tag">#hashtagtwo</a>'
)
assert parser.plain_text == "http://example.com#notahashtag #hashtag #hashtagtwo"
assert parser.hashtags == {"hashtag", "hashtagtwo"}
Expand Down

0 comments on commit e625fae

Please sign in to comment.