diff options
author | Travis Ralston <travpc@gmail.com> | 2021-02-02 07:26:36 -0700 |
---|---|---|
committer | Travis Ralston <travpc@gmail.com> | 2021-02-02 07:26:36 -0700 |
commit | 6ec034411cdad6f9f77f7dab7749d426ffd5744b (patch) | |
tree | d7935121ad99051eddf5769993bef674e618379e /tests/test_preview.py | |
parent | Appease the linters (diff) | |
parent | Update changelog (diff) | |
download | synapse-travis/fosdem/admin-api-groups.tar.xz |
Merge branch 'develop' into travis/fosdem/admin-api-groups github/travis/fosdem/admin-api-groups travis/fosdem/admin-api-groups
Diffstat (limited to 'tests/test_preview.py')
-rw-r--r-- | tests/test_preview.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/test_preview.py b/tests/test_preview.py index c19facc1cb..0c6cbbd921 100644 --- a/tests/test_preview.py +++ b/tests/test_preview.py @@ -261,3 +261,32 @@ class PreviewUrlTestCase(unittest.TestCase): html = "" og = decode_and_calc_og(html, "http://example.com/test.html") self.assertEqual(og, {}) + + def test_invalid_encoding(self): + """An invalid character encoding should be ignored and treated as UTF-8, if possible.""" + html = """ + <html> + <head><title>Foo</title></head> + <body> + Some text. + </body> + </html> + """ + og = decode_and_calc_og( + html, "http://example.com/test.html", "invalid-encoding" + ) + self.assertEqual(og, {"og:title": "Foo", "og:description": "Some text."}) + + def test_invalid_encoding2(self): + """A body which doesn't match the sent character encoding.""" + # Note that this contains an invalid UTF-8 sequence in the title. + html = b""" + <html> + <head><title>\xff\xff Foo</title></head> + <body> + Some text. + </body> + </html> + """ + og = decode_and_calc_og(html, "http://example.com/test.html") + self.assertEqual(og, {"og:title": "ÿÿ Foo", "og:description": "Some text."}) |