diff options
-rw-r--r-- | bs4/element.py | 10 | ||||
-rw-r--r-- | bs4/testing.py | 9 |
2 files changed, 15 insertions, 4 deletions
diff --git a/bs4/element.py b/bs4/element.py index 91a4007..744a4e0 100644 --- a/bs4/element.py +++ b/bs4/element.py @@ -1000,15 +1000,16 @@ class Tag(PageElement): attrs.append(decoded) close = '' closeTag = '' - if self.is_empty_element: - close = '/' - else: - closeTag = '</%s>' % self.name prefix = '' if self.prefix: prefix = self.prefix + ":" + if self.is_empty_element: + close = '/' + else: + closeTag = '</%s%s>' % (prefix, self.name) + pretty_print = (indent_level is not None) if pretty_print: space = (' ' * (indent_level - 1)) @@ -1120,6 +1121,7 @@ class Tag(PageElement): callable that takes a string and returns whether or not the string matches for some custom definition of 'matches'. The same is true of the tag name.""" + generator = self.descendants if not recursive: generator = self.children diff --git a/bs4/testing.py b/bs4/testing.py index 51f7e22..1487b1d 100644 --- a/bs4/testing.py +++ b/bs4/testing.py @@ -250,6 +250,11 @@ class HTMLTreeBuilderSmokeTest(object): self.assertEqual( 'http://www.w3.org/2000/svg', soup.html['xmlns:svg']) + def test_closing_namespaced_tag(self): + markup = '<p xmlns:dc="http://purl.org/dc/elements/1.1/"><dc:date>20010504</dc:date></p>' + soup = self.soup(markup) + self.assertEqual(unicode(soup.p), markup) + def test_multivalued_attribute_value_becomes_list(self): markup = b'<a class="foo bar">' soup = self.soup(markup) @@ -480,6 +485,10 @@ class XMLTreeBuilderSmokeTest(object): self.assertEqual("http://example.com/", root['xmlns:a']) self.assertEqual("http://example.net/", root['xmlns:b']) + def test_closing_namespaced_tag(self): + markup = '<p xmlns:dc="http://purl.org/dc/elements/1.1/"><dc:date>20010504</dc:date></p>' + soup = self.soup(markup) + self.assertEqual(unicode(soup.p), markup) class HTML5TreeBuilderSmokeTest(HTMLTreeBuilderSmokeTest): """Smoke test for a tree builder that supports HTML5.""" |