Skip to content

Commit

Permalink
microformats2.html_to_activities(): limit to h-entry, h-event, and h-…
Browse files Browse the repository at this point in the history
…cite items

fixes #192
  • Loading branch information
snarfed committed Mar 28, 2020
1 parent f4cd3e3 commit d8ee0bf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ Non-breaking changes:
* Handle malformed attachments better.
* microformats2:
* Don't crash on string `context` fields.
* `html_to_activities()`: limit to `h-entry`, `h-event`, and `h-cite` items ([#192](https://github.com/snarfed/granary/issues/192)).
* The `cache` kwarg to `Source.original_post_discovery()` now has no effect. `webutil.util.follow_redirects()` has its own built in caching now.
* Added Meetup.com support for publishing RSVPs.

Expand Down
8 changes: 5 additions & 3 deletions granary/microformats2.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,9 +587,11 @@ def html_to_activities(html, url=None, actor=None, id=None):

activities = []
for item in items:
obj = json_to_object(item, actor=actor)
obj['content_is_html'] = True
activities.append({'object': obj})
types = item.get('type', [])
if 'h-entry' in types or 'h-event' in types or 'h-cite' in types:
obj = json_to_object(item, actor=actor)
obj['content_is_html'] = True
activities.append({'object': obj})

return activities

Expand Down
9 changes: 9 additions & 0 deletions granary/tests/test_microformats2.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,15 @@ def test_html_to_activities_brs_to_newlines(self):
'displayName': 'foo bar\nbaz \n\n baj',
}}], activities)

def test_html_to_activities_filters_items(self):
"""Check that we omit h-cards inside h-feeds."""
self.assert_equals([], microformats2.html_to_activities("""\
<div class="h-feed">
<article class="h-card">
<a href="http://foo">bar</a>
</article>
</div>"""))

def test_size_to_bytes(self):
for input, expected in (
(None, None),
Expand Down

0 comments on commit d8ee0bf

Please sign in to comment.