diff options
author | Leonard Richardson <leonard.richardson@canonical.com> | 2011-01-28 21:39:20 -0500 |
---|---|---|
committer | Leonard Richardson <leonard.richardson@canonical.com> | 2011-01-28 21:39:20 -0500 |
commit | 23050015d14b227828c928433842cab11a1a783c (patch) | |
tree | fb615a7eeb282609e921e7fa43b8d4ea78c7ac88 /beautifulsoup/testing.py | |
parent | f0b1b4f0f3c2ce4e140ba01a6690ddb16bf0fb17 (diff) |
Added tests for <textarea> and <script> tags that contain HTML.
Diffstat (limited to 'beautifulsoup/testing.py')
-rw-r--r-- | beautifulsoup/testing.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/beautifulsoup/testing.py b/beautifulsoup/testing.py index eea14f0..9d0fa3a 100644 --- a/beautifulsoup/testing.py +++ b/beautifulsoup/testing.py @@ -119,6 +119,26 @@ class BuilderSmokeTest(SoupTest): self.assertSoupEquals('<this is="really messed up & stuff"></this>', '<this is="really messed up & stuff"></this>') + def test_literal_in_textarea(self): + # Anything inside a <textarea> is supposed to be treated as + # the literal value of the field, (XXX citation needed). + # + # But, both lxml and html5lib do their best to parse the + # contents of a <textarea> as HTML. + text = '<textarea>Junk like <b> tags and <&<&</textarea>' + soup = BeautifulSoup(text) + self.assertEquals(len(soup.textarea.contents), 2) + self.assertEquals(soup.textarea.contents[0], u"Junk like ") + self.assertEquals(soup.textarea.contents[1].name, 'b') + self.assertEquals(soup.textarea.b.string, u" tags and ") + + def test_literal_in_script(self): + # The contents of a <script> tag are treated as a literal string, + # even if that string contains HTML. + javascript = 'if (i < 2) { alert("<b>foo</b>"); }' + soup = BeautifulSoup('<script>%s</script>' % javascript) + self.assertEquals(soup.script.string, javascript) + class BuilderInvalidMarkupSmokeTest(SoupTest): """Tests of invalid markup. |