diff options
author | Leonard Richardson <leonardr@segfault.org> | 2013-05-06 17:13:43 -0400 |
---|---|---|
committer | Leonard Richardson <leonardr@segfault.org> | 2013-05-06 17:13:43 -0400 |
commit | 6bdd65ceb1177d0e5d50bbe51f21b1209c72b599 (patch) | |
tree | d5196eec6c5acf50e510e0f1cd929daaa8fbc652 /bs4/tests/test_tree.py | |
parent | eac207a4efeca3e7a78838377aafb4a2b44f43c5 (diff) |
In an HTML document, the contents of a <script> or <style> tag will
no longer undergo entity substitution by default. XML documents work
the same way they did before. [bug=1085953]
Diffstat (limited to 'bs4/tests/test_tree.py')
-rw-r--r-- | bs4/tests/test_tree.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/bs4/tests/test_tree.py b/bs4/tests/test_tree.py index 3e75fae..a4e2a8a 100644 --- a/bs4/tests/test_tree.py +++ b/bs4/tests/test_tree.py @@ -1317,16 +1317,28 @@ class TestSubstitutions(SoupTest): </script> """ encoded = BeautifulSoup(doc).encode() - self.assertTrue("< < hey > >" in encoded) + self.assertTrue(b"< < hey > >" in encoded) + + def test_formatter_skips_style_tag_for_html_documents(self): + doc = """ + <style type="text/css"> + console.log("< < hey > > "); + </style> +""" + encoded = BeautifulSoup(doc).encode() + self.assertTrue(b"< < hey > >" in encoded) def test_formatter_processes_script_tag_for_xml_documents(self): doc = """ <script type="text/javascript"> - console.log("< < hey > > "); </script> """ - encoded = BeautifulSoup(doc).encode() - self.assertTrue("< < hey > >" in encoded) + soup = BeautifulSoup(doc, "xml") + # lxml would have stripped this while parsing, but we can add + # it later. + soup.script.string = 'console.log("< < hey > > ");' + encoded = soup.encode() + self.assertTrue(b"< < hey > >" in encoded) def test_prettify_accepts_formatter(self): soup = BeautifulSoup("<html><body>foo</body></html>") |