kopia lustrzana https://github.com/snarfed/bridgy-fed
rodzic
2a4146fe74
commit
b6845246e9
10
common.py
10
common.py
|
@ -6,7 +6,7 @@ from pathlib import Path
|
|||
import re
|
||||
import threading
|
||||
import urllib.parse
|
||||
from urllib.parse import urljoin
|
||||
from urllib.parse import urljoin, urlparse
|
||||
|
||||
import cachetools
|
||||
from Crypto.Util import number
|
||||
|
@ -195,7 +195,15 @@ def unwrap(val, field=None):
|
|||
Returns:
|
||||
str: unwrapped url
|
||||
"""
|
||||
|
||||
if isinstance(val, dict):
|
||||
# TODO: clean up. https://github.com/snarfed/bridgy-fed/issues/967
|
||||
id = val.get('id')
|
||||
if (id and urlparse(id).path.strip('/') in DOMAINS + ('',)
|
||||
and util.domain_from_link(id) in DOMAINS):
|
||||
# protocol bot user, don't touch its URLs
|
||||
return {**val, 'id': unwrap(id)}
|
||||
|
||||
return {f: unwrap(v, field=f) for f, v in val.items()}
|
||||
|
||||
elif isinstance(val, list):
|
||||
|
|
|
@ -628,6 +628,26 @@ class ObjectTest(TestCase):
|
|||
self.assertEqual({'id': 'x', 'foo': 'bar'},
|
||||
Object(id='x', our_as1={'foo': 'bar'}).as1)
|
||||
|
||||
def test_as1_from_as2_protocol_bot_user(self):
|
||||
self.assert_equals({
|
||||
'objectType': 'application',
|
||||
'id': 'fed.brid.gy',
|
||||
'url': 'https://fed.brid.gy/',
|
||||
'displayName': 'Bridgy Fed',
|
||||
'summary': 'Bridging the new social internet',
|
||||
'username': 'fed.brid.gy',
|
||||
'image': [{
|
||||
'displayName': 'Bridgy Fed',
|
||||
'url': 'https://fed.brid.gy/static/bridgy_logo_square.jpg',
|
||||
}, {
|
||||
'url': 'https://fed.brid.gy/static/bridgy_logo.jpg',
|
||||
}],
|
||||
'attachments': [{
|
||||
'displayName': 'Web site',
|
||||
'value': '<a rel="me" href="https://fed.brid.gy"><span class="invisible">https://</span>fed.brid.gy</a>',
|
||||
}],
|
||||
}, Web.load('https://fed.brid.gy/').as1)
|
||||
|
||||
def test_atom_url_overrides_id(self):
|
||||
obj = {
|
||||
'objectType': 'note',
|
||||
|
|
Ładowanie…
Reference in New Issue