diff options
author | Leonard Richardson <leonardr@segfault.org> | 2018-07-30 20:19:51 -0400 |
---|---|---|
committer | Leonard Richardson <leonardr@segfault.org> | 2018-07-30 20:19:51 -0400 |
commit | 6ef9b0c70abf4237ed07cb8314a7ef5b67d35869 (patch) | |
tree | d051c868e373221f055caf814c7ffb823e0d6141 | |
parent | 269f7ddc8d12c1d342abf23af81c73958ebb2318 (diff) | |
download | beautifulsoup4-6ef9b0c70abf4237ed07cb8314a7ef5b67d35869.tar.gz |
Fix an exception when a custom formatter was asked to format a void
element. [bug=1784408]
-rw-r--r-- | LICENSE | 2 | ||||
-rw-r--r-- | NEWS.txt | 5 | ||||
-rw-r--r-- | bs4/__init__.py | 2 | ||||
-rw-r--r-- | bs4/element.py | 4 | ||||
-rw-r--r-- | bs4/tests/test_tree.py | 4 | ||||
-rw-r--r-- | prepare-release.sh | 34 |
6 files changed, 30 insertions, 21 deletions
@@ -1,6 +1,6 @@ Beautiful Soup is made available under the MIT license: - Copyright (c) 2004-2016 Leonard Richardson + Copyright (c) 2004-2018 Leonard Richardson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -1,3 +1,8 @@ += 4.6.2 (unreleased) + +* Fix an exception when a custom formatter was asked to format a void + element. [bug=1784408] + = 4.6.1 (20180728) * Stop data loss when encountering an empty numeric entity, and 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><foo></b><b>bar</b>" + markup = u"<b><foo></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>' diff --git a/prepare-release.sh b/prepare-release.sh index c278b67..ff3f6c0 100644 --- a/prepare-release.sh +++ b/prepare-release.sh @@ -17,7 +17,7 @@ rm -rf build dist python setup.py sdist bdist_wheel # Upload the 2.x source distro and wheel to pypi test -python setup.py register -r test +# python setup.py register -r test python setup.py sdist bdist_wheel upload -r test # Try 2.x install from pypi test @@ -35,7 +35,7 @@ rm -rf ../py2-install-test-virtualenv rm -rf ../py3-source-install virtualenv -p /usr/bin/python3 ../py3-source-install source ../py3-source-install/bin/activate -pip install -i https://testpypi.python.org/pypi beautifulsoup4 +pip3 install -i https://testpypi.python.org/pypi beautifulsoup4 echo "EXPECT HTML ON LINE BELOW" (cd .. && python -c "from bs4 import _s; print(_s('<a>foo', 'html.parser'))") # That should print '<a>foo</a>' @@ -90,8 +90,8 @@ echo rm -rf ../py3-install-test-virtualenv virtualenv -p /usr/bin/python3 ../py3-install-test-virtualenv source ../py3-install-test-virtualenv/bin/activate -pip install --upgrade setuptools -pip install dist/beautifulsoup4-4.*-py3-none-any.whl -e .[html5lib] +pip3 install --upgrade setuptools +pip3 install dist/beautifulsoup4-4.*-py3-none-any.whl -e .[html5lib] echo "EXPECT HTML ON LINE BELOW" (cd .. && python -c "from bs4 import _s; print(_s('<a>foo', 'html5lib'))") # That should print '<html><head></head><body><a>foo</a></body></html>' @@ -102,28 +102,30 @@ rm -rf ../py3-install-test-virtualenv Do the release for real. +twine upload dist/* + # Register the project and upload the source distribution and Python 2 wheel. -python setup.py register -python setup.py sdist bdist_wheel upload +# python setup.py register +# python setup.py sdist bdist_wheel upload # Create a Python 3 environment and install Beautiful Soup # from the source distribution that was just uploaded -rm -rf ../py3-source-install -virtualenv -p /usr/bin/python3 ../py3-source-install -source ../py3-source-install/bin/activate -pip install -i https://pypi.python.org/pypi beautifulsoup4 -echo "EXPECT HTML ON LINE BELOW" -(cd .. && python -c "from bs4 import _s; print(_s('<a>foo', 'html.parser'))") +#rm -rf ../py3-source-install +#virtualenv -p /usr/bin/python3 ../py3-source-install +#source ../py3-source-install/bin/activate +#pip install -i https://pypi.python.org/pypi beautifulsoup4 +#echo "EXPECT HTML ON LINE BELOW" +#(cd .. && python -c "from bs4 import _s; print(_s('<a>foo', 'html.parser'))") # That should print '<a>foo</a>' # Create and upload a Python 3 wheel from within a virtual environment # that has the Python 3 version of the code. -pip install wheel -python3 setup.py bdist_wheel upload +#pip install wheel +#python3 setup.py bdist_wheel upload # Remove the Python 3 virtual environment. -deactivate -rm -rf ../py3-source-install +#deactivate +#rm -rf ../py3-source-install ################ |