summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeonard Richardson <leonard.richardson@canonical.com>2012-03-01 11:54:25 -0500
committerLeonard Richardson <leonard.richardson@canonical.com>2012-03-01 11:54:25 -0500
commit483286bfbb40bfabe4c48c9f31c59ef7449d64bb (patch)
treeae5b39346a0763444d981c66a1649abf3b36e8a9
parentae493c3544d07f0879c8a14e17d48b69c3c82772 (diff)
Added missing __len__ method that stopped html5lib tree builder from working on nested formatting elements. [bug=943246]
-rw-r--r--bs4/builder/_html5lib.py2
-rw-r--r--bs4/testing.py3
2 files changed, 5 insertions, 0 deletions
diff --git a/bs4/builder/_html5lib.py b/bs4/builder/_html5lib.py
index cf716df..b8c2bb6 100644
--- a/bs4/builder/_html5lib.py
+++ b/bs4/builder/_html5lib.py
@@ -107,6 +107,8 @@ class AttrList(object):
return list(self.attrs.items())
def keys(self):
return list(self.attrs.keys())
+ def __len__(self):
+ return len(self.attrs)
def __getitem__(self, name):
return self.attrs[name]
def __contains__(self, name):
diff --git a/bs4/testing.py b/bs4/testing.py
index 717e721..a3e0b38 100644
--- a/bs4/testing.py
+++ b/bs4/testing.py
@@ -132,6 +132,9 @@ class HTMLTreeBuilderSmokeTest(object):
self.assertTrue(soup.br.is_empty_element)
self.assertEqual(str(soup.br), "<br/>")
+ def test_nested_formatting_elements(self):
+ self.assertSoupEquals("<em><em></em></em>")
+
def test_comment(self):
# Comments are represented as Comment objects.
markup = "<p>foo<!--foobar-->baz</p>"