diff options
author | Patrick Cloke <clokep@users.noreply.github.com> | 2022-06-16 07:41:57 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-16 07:41:57 -0400 |
commit | 0fcc0ae37c959116c910f349a8025bd6921fdfc8 (patch) | |
tree | 31f36fa01941627e43c33c496910af5a1a07a8e1 /tests/rest | |
parent | Reduce the duplication of code that invokes the rate limiter. (#13070) (diff) | |
download | synapse-0fcc0ae37c959116c910f349a8025bd6921fdfc8.tar.xz |
Improve URL previews for sites with only Twitter card information. (#13056)
Pull out `twitter:` meta tags when generating a preview and use it to augment any `og:` meta tags. Prefers Open Graph information over Twitter card information.
Diffstat (limited to 'tests/rest')
-rw-r--r-- | tests/rest/media/v1/test_html_preview.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/rest/media/v1/test_html_preview.py b/tests/rest/media/v1/test_html_preview.py index ea9e5889bf..cbdf210aef 100644 --- a/tests/rest/media/v1/test_html_preview.py +++ b/tests/rest/media/v1/test_html_preview.py @@ -370,6 +370,47 @@ class OpenGraphFromHtmlTestCase(unittest.TestCase): og = parse_html_to_open_graph(tree) self.assertEqual(og, {"og:title": "รณ", "og:description": "Some text."}) + def test_twitter_tag(self) -> None: + """Twitter card tags should be used if nothing else is available.""" + html = b""" + <html> + <meta name="twitter:card" content="summary"> + <meta name="twitter:description" content="Description"> + <meta name="twitter:site" content="@matrixdotorg"> + </html> + """ + tree = decode_body(html, "http://example.com/test.html") + og = parse_html_to_open_graph(tree) + self.assertEqual( + og, + { + "og:title": None, + "og:description": "Description", + "og:site_name": "@matrixdotorg", + }, + ) + + # But they shouldn't override Open Graph values. + html = b""" + <html> + <meta name="twitter:card" content="summary"> + <meta name="twitter:description" content="Description"> + <meta property="og:description" content="Real Description"> + <meta name="twitter:site" content="@matrixdotorg"> + <meta property="og:site_name" content="matrix.org"> + </html> + """ + tree = decode_body(html, "http://example.com/test.html") + og = parse_html_to_open_graph(tree) + self.assertEqual( + og, + { + "og:title": None, + "og:description": "Real Description", + "og:site_name": "matrix.org", + }, + ) + class MediaEncodingTestCase(unittest.TestCase): def test_meta_charset(self) -> None: |