summaryrefslogtreecommitdiff
path: root/bs4
diff options
context:
space:
mode:
authorLeonard Richardson <leonardr@segfault.org>2018-07-30 20:19:51 -0400
committerLeonard Richardson <leonardr@segfault.org>2018-07-30 20:19:51 -0400
commit6ef9b0c70abf4237ed07cb8314a7ef5b67d35869 (patch)
treed051c868e373221f055caf814c7ffb823e0d6141 /bs4
parent269f7ddc8d12c1d342abf23af81c73958ebb2318 (diff)
downloadbeautifulsoup4-6ef9b0c70abf4237ed07cb8314a7ef5b67d35869.tar.gz
Fix an exception when a custom formatter was asked to format a void
element. [bug=1784408]
Diffstat (limited to 'bs4')
-rw-r--r--bs4/__init__.py2
-rw-r--r--bs4/element.py4
-rw-r--r--bs4/tests/test_tree.py4
3 files changed, 6 insertions, 4 deletions
diff --git a/bs4/__init__.py b/bs4/__init__.py
index ac3c172..8c662f8 100644
--- a/bs4/__init__.py
+++ b/bs4/__init__.py
@@ -21,7 +21,7 @@ http://www.crummy.com/software/BeautifulSoup/bs4/doc/
# found in the LICENSE file.
__author__ = "Leonard Richardson (leonardr@segfault.org)"
-__version__ = "4.6.1"
+__version__ = "4.6.2"
__copyright__ = "Copyright (c) 2004-2018 Leonard Richardson"
__license__ = "MIT"
diff --git a/bs4/element.py b/bs4/element.py
index 8383c3f..886eb91 100644
--- a/bs4/element.py
+++ b/bs4/element.py
@@ -1223,7 +1223,9 @@ class Tag(PageElement):
prefix = self.prefix + ":"
if self.is_empty_element:
- close = formatter.void_element_close_prefix or ''
+ close = ''
+ if isinstance(formatter, Formatter):
+ close = formatter.void_element_close_prefix or close
else:
closeTag = '</%s%s>' % (prefix, self.name)
diff --git a/bs4/tests/test_tree.py b/bs4/tests/test_tree.py
index 68887b4..883cd8a 100644
--- a/bs4/tests/test_tree.py
+++ b/bs4/tests/test_tree.py
@@ -1474,14 +1474,14 @@ class TestSubstitutions(SoupTest):
self.document_for(u"<b><<Sacr\N{LATIN SMALL LETTER E WITH ACUTE} bleu!>></b>"))
def test_formatter_custom(self):
- markup = u"<b>&lt;foo&gt;</b><b>bar</b>"
+ markup = u"<b>&lt;foo&gt;</b><b>bar</b><br/>"
soup = self.soup(markup)
decoded = soup.decode(formatter = lambda x: x.upper())
# Instead of normal entity conversion code, the custom
# callable is called on every string.
self.assertEqual(
decoded,
- self.document_for(u"<b><FOO></b><b>BAR</b>"))
+ self.document_for(u"<b><FOO></b><b>BAR</b><br>"))
def test_formatter_is_run_on_attribute_values(self):
markup = u'<a href="http://a.com?a=b&c=é">e</a>'