diff options
author | Erik Johnston <erik@matrix.org> | 2021-11-02 14:28:27 +0000 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2021-11-02 14:28:27 +0000 |
commit | 237f7eb87ad097ecf40f945630ac49cef1aa1154 (patch) | |
tree | 2fb7f95f8130b4756b5603ff8994c687c8726a9e /tests | |
parent | Add remaining type hints to `synapse.events`. (#11098) (diff) | |
parent | Update changelog (diff) | |
download | synapse-237f7eb87ad097ecf40f945630ac49cef1aa1154.tar.xz |
Merge remote-tracking branch 'origin/master' into develop
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_preview.py | 15 |
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""" |