Skip to content

Commit

Permalink
bluesky.from_as1: ignore contentMap languages that aren't valid BCP47…
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Dec 12, 2024
1 parent 7346709 commit df0bbae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
7 changes: 4 additions & 3 deletions granary/bluesky.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from bs4 import BeautifulSoup
from lexrpc import Client
from lexrpc.base import Base, NSID_RE
from lexrpc.base import Base, LANG_RE, NSID_RE
from multiformats import CID
from oauth_dropins.webutil import util
from oauth_dropins.webutil.util import trim_nulls
Expand Down Expand Up @@ -955,7 +955,7 @@ def from_as1(obj, out_type=None, blobs=None, aspects=None, client=None,
embed = {
'$type': 'app.bsky.embed.recordWithMedia#view',
'record': record_embed,
'media': media_embed
'media': media_embed,
}
else:
embed = record_embed or media_embed
Expand Down Expand Up @@ -986,7 +986,8 @@ def from_as1(obj, out_type=None, blobs=None, aspects=None, client=None,
# languages
# (we steal contentMap from AS2, it's not officially part of AS1)
langs = [lang for lang, lang_content in obj.get('contentMap', {}).items()
if lang_content == orig_content]
if LANG_RE.match(lang)
and lang_content == orig_content]

# convert AS1 sensitive to "nudity" label
# https://github.com/snarfed/atproto/blob/f2f8de63b333448d87c364578e023ddbb63b8b25/lexicons/com/atproto/label/defs.json#L139-L154
Expand Down
13 changes: 13 additions & 0 deletions granary/tests/test_bluesky.py
Original file line number Diff line number Diff line change
Expand Up @@ -1663,6 +1663,19 @@ def test_from_as1_post_langs(self):
},
}))

def test_from_as1_post_bad_lang(self):
self.assert_equals({
'$type': 'app.bsky.feed.post',
'text': 'My original post',
'createdAt': '2022-01-02T03:04:05.000Z',
}, from_as1({
'objectType': 'note',
'content': 'My original post',
'contentMap': {
'unknown': 'My original post',
},
}))

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

0 comments on commit df0bbae

Please sign in to comment.