summary refs log tree commit diff
path: root/tests/test_preview.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2021-11-02 10:04:06 +0000
committerErik Johnston <erik@matrix.org>2021-11-02 10:04:06 +0000
commit459d2ae1579dbfe3ceea94e3839d22f3b285ecbb (patch)
tree9322693c9e5896b787f2e29d7617af2f2793ceaf /tests/test_preview.py
parentDon't seqscan event_json due to relates_to_id (diff)
parentForce deb compression with `xz`. (#11197) (diff)
downloadsynapse-459d2ae1579dbfe3ceea94e3839d22f3b285ecbb.tar.xz
Merge remote-tracking branch 'origin/release-v1.46' into matrix-org-hotfixes
Diffstat (limited to 'tests/test_preview.py')
-rw-r--r--tests/test_preview.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/test_preview.py b/tests/test_preview.py

index 9a576f9a4e..40b89fb2ef 100644 --- a/tests/test_preview.py +++ b/tests/test_preview.py
@@ -277,6 +277,21 @@ class CalcOgTestCase(unittest.TestCase): tree = decode_body(html, "http://example.com/test.html") self.assertIsNone(tree) + def test_xml(self): + """Test decoding XML and ensure it works properly.""" + # Note that the strip() call is important to ensure the xml tag starts + # at the initial byte. + html = b""" + <?xml version="1.0" encoding="UTF-8"?> + + <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> + <head><title>Foo</title></head><body>Some text.</body></html> + """.strip() + tree = decode_body(html, "http://example.com/test.html") + og = _calc_og(tree, "http://example.com/test.html") + self.assertEqual(og, {"og:title": "Foo", "og:description": "Some text."}) + def test_invalid_encoding(self): """An invalid character encoding should be ignored and treated as UTF-8, if possible.""" html = b"""