diff options
author | Leonard Richardson <leonardr@segfault.org> | 2020-04-05 15:43:58 -0400 |
---|---|---|
committer | Leonard Richardson <leonardr@segfault.org> | 2020-04-05 15:43:58 -0400 |
commit | a6f897b213bb08f0d8d8a1528937541c280abbd6 (patch) | |
tree | 866d3392a854ea27a172e9b456b2160307e39363 /bs4/testing.py | |
parent | ddadf13ef66122d75eadaf7f10e0937429e6a3a6 (diff) |
Embedded CSS and Javascript is now stored in distinct Stylesheet and
Script tags, which are ignored by methods like get_text(). This
feature is not supported by the html5lib treebuilder. [bug=1868861]
Diffstat (limited to 'bs4/testing.py')
-rw-r--r-- | bs4/testing.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/bs4/testing.py b/bs4/testing.py index a162778..328bd56 100644 --- a/bs4/testing.py +++ b/bs4/testing.py @@ -16,6 +16,8 @@ from bs4.element import ( ContentMetaAttributeValue, Doctype, SoupStrainer, + Script, + Stylesheet, Tag ) @@ -233,6 +235,22 @@ class HTMLTreeBuilderSmokeTest(object): new_tag = soup.new_tag(name) self.assertEqual(True, new_tag.is_empty_element) + def test_special_string_containers(self): + soup = self.soup( + "<style>Some CSS</style><script>Some Javascript</script>" + ) + assert isinstance(soup.style.string, Stylesheet) + assert isinstance(soup.script.string, Script) + + soup = self.soup( + "<style><!--Some CSS--></style>" + ) + assert isinstance(soup.style.string, Stylesheet) + # The contents of the style tag resemble an HTML comment, but + # it's not treated as a comment. + self.assertEqual("<!--Some CSS-->", soup.style.string) + assert isinstance(soup.style.string, Stylesheet) + def test_pickle_and_unpickle_identity(self): # Pickling a tree, then unpickling it, yields a tree identical # to the original. |