diff options
author | Patrick Cloke <clokep@users.noreply.github.com> | 2022-06-03 12:09:12 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-03 12:09:12 -0400 |
commit | 01df5bacac3aa0e8356fed889ea0b69c4c044535 (patch) | |
tree | 46bae7592ce241b95a9a88ecccb9ff8df3717733 /tests/rest/media | |
parent | Wait for lazy join to complete when getting current state (#12872) (diff) | |
download | synapse-01df5bacac3aa0e8356fed889ea0b69c4c044535.tar.xz |
Improve URL previews for some pages (#12951)
* Skip `og` and `meta` tags where the value is empty. * Fallback to the favicon if there are no other images. * Ignore tags meant for navigation.
Diffstat (limited to 'tests/rest/media')
-rw-r--r-- | tests/rest/media/v1/test_html_preview.py | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/tests/rest/media/v1/test_html_preview.py b/tests/rest/media/v1/test_html_preview.py index 62e308814d..ea9e5889bf 100644 --- a/tests/rest/media/v1/test_html_preview.py +++ b/tests/rest/media/v1/test_html_preview.py @@ -145,7 +145,7 @@ class SummarizeTestCase(unittest.TestCase): ) -class CalcOgTestCase(unittest.TestCase): +class OpenGraphFromHtmlTestCase(unittest.TestCase): if not lxml: skip = "url preview feature requires lxml" @@ -235,6 +235,21 @@ class CalcOgTestCase(unittest.TestCase): self.assertEqual(og, {"og:title": None, "og:description": "Some text."}) + # Another variant is a title with no content. + html = b""" + <html> + <head><title></title></head> + <body> + <h1>Title</h1> + </body> + </html> + """ + + tree = decode_body(html, "http://example.com/test.html") + og = parse_html_to_open_graph(tree) + + self.assertEqual(og, {"og:title": "Title", "og:description": "Title"}) + def test_h1_as_title(self) -> None: html = b""" <html> @@ -250,6 +265,26 @@ class CalcOgTestCase(unittest.TestCase): self.assertEqual(og, {"og:title": "Title", "og:description": "Some text."}) + def test_empty_description(self) -> None: + """Description tags with empty content should be ignored.""" + html = b""" + <html> + <meta property="og:description" content=""/> + <meta property="og:description"/> + <meta name="description" content=""/> + <meta name="description"/> + <meta name="description" content="Finally!"/> + <body> + <h1>Title</h1> + </body> + </html> + """ + + tree = decode_body(html, "http://example.com/test.html") + og = parse_html_to_open_graph(tree) + + self.assertEqual(og, {"og:title": "Title", "og:description": "Finally!"}) + def test_missing_title_and_broken_h1(self) -> None: html = b""" <html> |