diff --git a/README.md b/README.md
index b0401cb9..9d1e7178 100644
--- a/README.md
+++ b/README.md
@@ -331,7 +331,7 @@ _Non-breaking changes:_
* `status_to_object`: add/fix alt text handling for images.
* `microformats2`:
* `json_to_html`:
- * HTML-escape tag names. Fixes [GHSA-4w4f-g49g-3f7j](https://github.com/snarfed/bridgy/security/advisories/GHSA-4w4f-g49g-3f7j); thank you [@janboddez](https://github.com/janboddez)!
+ * HTML-escape tag and quote attachment names. Fixes [GHSA-4w4f-g49g-3f7j](https://github.com/snarfed/bridgy/security/advisories/GHSA-4w4f-g49g-3f7j); thank you [@janboddez](https://github.com/janboddez)!
* `json_to_object`:
* Improve handling of items with multiple types by using [post type discovery](https://indiewebcamp.com/post-type-discovery) more aggressively.
* Normalize ISO-8601 format of `published` and `updated` timestamps.
diff --git a/granary/microformats2.py b/granary/microformats2.py
index fa482b64..e672eb82 100644
--- a/granary/microformats2.py
+++ b/granary/microformats2.py
@@ -137,7 +137,9 @@ def get_html(val):
Returns:
string or None
"""
- if isinstance(val, dict) and val.get('html'):
+ if val is None:
+ return None
+ elif isinstance(val, dict) and val.get('html'):
return val['html'].strip()
return html.escape(get_text(val), quote=False)
@@ -789,7 +791,9 @@ def json_to_html(obj, parent_props=None):
props['name'] = [{'yes': 'is attending.',
'no': 'is not attending.',
'maybe': 'might attend.'}.get(rsvp)]
- props['name'][0] = f"{props['name'][0]}"
+ props['name'][0] = {
+ 'html': f"{props['name'][0]}",
+ }
elif props.get('invitee') and not props.get('name'):
props['name'] = ['invited']
@@ -1242,7 +1246,7 @@ def maybe_linked_name(props):
string HTML
"""
prop = first_props(props)
- name = prop.get('name')
+ name = get_html(prop.get('name'))
url = prop.get('url')
if name is not None:
diff --git a/granary/tests/test_microformats2.py b/granary/tests/test_microformats2.py
index 2b5fc012..85ee5973 100644
--- a/granary/tests/test_microformats2.py
+++ b/granary/tests/test_microformats2.py
@@ -666,6 +666,14 @@ def test_tags_to_html_escapes_html(self):
'displayName': '',
}], 'tag'))
+ def test_maybe_linked_name_escapes_html(self):
+ self.assert_equals(
+ '<bar>',
+ microformats2.maybe_linked_name({
+ 'url': ['http://foo'],
+ 'name': [''],
+ }))
+
def test_json_to_object_with_location_hcard(self):
obj = microformats2.json_to_object({
'type': ['h-entry'],