Skip to content

Commit

Permalink
bluesky.from_as1: account for … char when trimming facets off the end
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed May 18, 2024
1 parent 17686a4 commit 0418f80
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions granary/bluesky.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,8 @@ def from_as1(obj, out_type=None, blobs=None, client=None):
# skip or trim this facet if it's off the end of content that got truncated
index = facet.get('index')
text_len = len(text.encode())
if truncated:
text_len -= len('…'.encode())
if index.get('byteStart', 0) >= text_len:
continue
if index.get('byteEnd', 0) > text_len:
Expand Down
11 changes: 11 additions & 0 deletions granary/tests/test_bluesky.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,17 @@ def test_from_as1_html_link(self):
'content': 'foo <a href="http://post">ba]r</a> baz',
}))

@patch.object(Bluesky, 'TRUNCATE_TEXT_LENGTH', 12)
def test_from_as1_html_omit_link_facet_after_truncation(self):
self.assert_equals({
'$type': 'app.bsky.feed.post',
'createdAt': '2022-01-02T03:04:05.000Z',
'text': 'foo bar…',
}, from_as1({
'objectType': 'note',
'content': 'foo bar <a href="http://post">baaaaaaaz</a>',
}))

def test_from_as1_link_mention_hashtag(self):
self.assert_equals({
'$type': 'app.bsky.feed.post',
Expand Down

0 comments on commit 0418f80

Please sign in to comment.