kopia lustrzana https://github.com/snarfed/bridgy-fed
Web.fetch: ignore uid if set; we use URL as id
props and thanks to @fluffy-critter for being my unintentional edge case QA department 😆🙏 fixes https://console.cloud.google.com/errors/detail/CKLuk-v4x8X0NQ;time=P30D?project=bridgy-federatedpull/736/head
rodzic
3c460c88ad
commit
dc3b23f80b
|
@ -20,7 +20,7 @@ from web import Web
|
|||
COMMENT_AS2 = {
|
||||
**as2.from_as1(COMMENT),
|
||||
'type': 'Note',
|
||||
'id': 'https://web.brid.gy/r/tag:fake.com:123456',
|
||||
'id': 'https://fed.brid.gy/r/https://fake.com/123456',
|
||||
'url': 'https://web.brid.gy/r/https://fake.com/123456',
|
||||
'name': 'A ☕ reply',
|
||||
'contentMap': {'en': COMMENT['content']},
|
||||
|
@ -33,7 +33,6 @@ HTML = """\
|
|||
<meta http-equiv="refresh" content="0;url=https://fake.com/123456"></head>
|
||||
<body class="">
|
||||
<article class="h-entry">
|
||||
<span class="p-uid">tag:fake.com:123456</span>
|
||||
<time class="dt-published" datetime="2012-12-05T00:58:26+00:00">2012-12-05T00:58:26+00:00</time>
|
||||
<a class="u-url" href="https://fake.com/123456">fake.com/123456</a>
|
||||
<div class="e-content p-name">
|
||||
|
|
|
@ -2126,6 +2126,20 @@ class WebUtilTest(TestCase):
|
|||
'url': 'https://user.com/post',
|
||||
}, obj.mf2)
|
||||
|
||||
def test_load_id_is_url_not_uid(self, mock_get, __):
|
||||
mock_get.return_value = requests_response(NOTE_HTML.replace(
|
||||
'<a href="http://localhost/"></a>', """\
|
||||
<data class="p-uid" value="abc123"></data>
|
||||
<a href="http://localhost/"></a>
|
||||
"""))
|
||||
|
||||
obj = Web.load('https://user.com/post')
|
||||
self.assertEqual('https://user.com/post', obj.key.id())
|
||||
self.assertEqual('https://user.com/post', obj.as1['id'])
|
||||
|
||||
self.assertEqual(NOTE_MF2, obj.mf2)
|
||||
self.assertNotIn('uid', obj.mf2['properties'])
|
||||
|
||||
def test_fetch_user_homepage(self, mock_get, __):
|
||||
mock_get.return_value = ACTOR_HTML_RESP
|
||||
|
||||
|
|
7
web.py
7
web.py
|
@ -401,12 +401,17 @@ class Web(User, Protocol):
|
|||
if not entry:
|
||||
error(f'No microformats2 h-entry found in {url}')
|
||||
|
||||
# discard uid if set; we use URL as id
|
||||
props = entry.setdefault('properties', {})
|
||||
if 'uid' in props:
|
||||
logger.info(f'Discarding uid property: {props["uid"]}')
|
||||
props.pop('uid')
|
||||
|
||||
# store final URL in mf2 object, and also default url property to it,
|
||||
# since that's the fallback for AS1/AS2 id
|
||||
if is_homepage:
|
||||
entry.setdefault('rel-urls', {}).update(parsed.get('rel-urls', {}))
|
||||
entry.setdefault('type', ['h-card'])
|
||||
props = entry.setdefault('properties', {})
|
||||
if parsed['url']:
|
||||
entry['url'] = parsed['url']
|
||||
props.setdefault('url', [parsed['url']])
|
||||
|
|
Ładowanie…
Reference in New Issue