From f93d5bf81e56515098785068a18f2befec37857a Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Sun, 13 Feb 2011 21:42:50 -0500 Subject: Ported more tests of bad declarations. --- tests/test_html5lib.py | 22 ++++++++++++++++++++++ tests/test_lxml.py | 11 +++++++++++ 2 files changed, 33 insertions(+) (limited to 'tests') diff --git a/tests/test_html5lib.py b/tests/test_html5lib.py index 48f27ae..3efdebf 100644 --- a/tests/test_html5lib.py +++ b/tests/test_html5lib.py @@ -107,6 +107,28 @@ class TestHTML5BuilderInvalidMarkup(TestLXMLBuilderInvalidMarkup): ("

a

" "")) + def test_whitespace_in_doctype(self): + # A declaration that has extra whitespace is turned into a comment. + soup = self.soup(( + '' + '

foo

')) + self.assertEquals( + str(soup), + ('' + '

foo

')) + + def test_incomplete_declaration(self): + # An incomplete declaration is treated as a comment. + markup = 'ac' + self.assertSoupEquals(markup, "ac") + + # Let's spell that out a little more explicitly. + soup = self.soup(markup) + str1, comment, str2 = soup.body.contents + self.assertEquals(str1, 'a') + self.assertEquals(comment.__class__, Comment) + self.assertEquals(comment, 'b Sacr\xe9 bleu!""" diff --git a/tests/test_lxml.py b/tests/test_lxml.py index cba5522..6adc2b3 100644 --- a/tests/test_lxml.py +++ b/tests/test_lxml.py @@ -302,6 +302,17 @@ class TestLXMLBuilderInvalidMarkup(SoupTest): # Declarations that don't make any sense are ignored. self.assertSoupEquals('

a

', "

a

") + def test_whitespace_in_doctype(self): + # A declaration that has extra whitespace is ignored. + self.assertSoupEquals( + ('' + '

foo

'), + '

foo

') + + def test_incomplete_declaration(self): + # An incomplete declaration will screw up the rest of the document. + self.assertSoupEquals('ac', '

a

') + def test_cdata_where_it_doesnt_belong(self): #CDATA sections are ignored. markup = "
" -- cgit v1.2.3