diff options
author | Patrick Cloke <clokep@users.noreply.github.com> | 2021-10-27 10:48:02 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-27 14:48:02 +0000 |
commit | b3e843be88d67633d11711ecc80d4e0390b1e723 (patch) | |
tree | 77f33ea6e023273ceee7bc2fa97d3551c103bfef /tests | |
parent | Update release date (diff) | |
download | synapse-b3e843be88d67633d11711ecc80d4e0390b1e723.tar.xz |
Fix URL preview errors when previewing XML documents. (#11196)
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""" |