diff options
author | Leonard Richardson <leonardr@segfault.org> | 2022-04-10 13:42:02 -0400 |
---|---|---|
committer | Leonard Richardson <leonardr@segfault.org> | 2022-04-10 13:42:02 -0400 |
commit | 92b50fc6ae57038a09e9cace20604613b1b345e8 (patch) | |
tree | e695bca9b85d605272dee2128ffd4fe69af4b0d5 | |
parent | bae2e2ca3565a75fcff1d2bc911f0a2e022761b4 (diff) |
Fixed another crash when overriding multi_valued_attributes and using the
html5lib parser. [bug=1948488]
-rw-r--r-- | CHANGELOG | 5 | ||||
-rw-r--r-- | bs4/builder/__init__.py | 2 | ||||
-rw-r--r-- | bs4/builder/_html5lib.py | 4 | ||||
-rw-r--r-- | bs4/tests/__init__.py | 4 | ||||
-rw-r--r-- | prepare-release.sh | 2 |
5 files changed, 11 insertions, 6 deletions
@@ -3,6 +3,11 @@ Beautiful Soup's official support for Python 2 ended on January 1st, 4.9.3. In the Launchpad Bazaar repository, the final revision to support Python 2 was revision 605. += Unreleased + +* Fixed another crash when overriding multi_valued_attributes and using the + html5lib parser. [bug=1948488] + = 4.11.1 (20220408) This release was done to ensure that the unit tests are packaged along diff --git a/bs4/builder/__init__.py b/bs4/builder/__init__.py index 9f789f3..2e39745 100644 --- a/bs4/builder/__init__.py +++ b/bs4/builder/__init__.py @@ -122,7 +122,7 @@ class TreeBuilder(object): # A value for these tag/attribute combinations is a space- or # comma-separated list of CDATA, rather than a single CDATA. - DEFAULT_CDATA_LIST_ATTRIBUTES = {} + DEFAULT_CDATA_LIST_ATTRIBUTES = defaultdict(list) # Whitespace should be preserved inside these tags. DEFAULT_PRESERVE_WHITESPACE_TAGS = set() diff --git a/bs4/builder/_html5lib.py b/bs4/builder/_html5lib.py index 58bc176..12dee07 100644 --- a/bs4/builder/_html5lib.py +++ b/bs4/builder/_html5lib.py @@ -249,9 +249,9 @@ class AttrList(object): # If this attribute is a multi-valued attribute for this element, # turn its value into a list. list_attr = self.element.cdata_list_attributes or {} - if (name in list_attr.get('*') + if (name in list_attr.get('*', []) or (self.element.name in list_attr - and name in list_attr[self.element.name])): + and name in list_attr.get(self.element.name, []))): # A node that is being cloned may have already undergone # this procedure. if not isinstance(value, list): diff --git a/bs4/tests/__init__.py b/bs4/tests/__init__.py index 4af4b0c..7f8b620 100644 --- a/bs4/tests/__init__.py +++ b/bs4/tests/__init__.py @@ -258,10 +258,10 @@ class TreeBuilderSmokeTest(object): @pytest.mark.parametrize( "multi_valued_attributes", - [None, dict(b=['class']), {'*': ['notclass']}] + [None, {}, dict(b=['class']), {'*': ['notclass']}] ) def test_attribute_not_multi_valued(self, multi_valued_attributes): - markup = '<a class="a b c">' + markup = '<html xmlns="http://www.w3.org/1999/xhtml"><a class="a b c"></html>' soup = self.soup(markup, multi_valued_attributes=multi_valued_attributes) assert soup.a['class'] == 'a b c' diff --git a/prepare-release.sh b/prepare-release.sh index 29604a2..dc6054f 100644 --- a/prepare-release.sh +++ b/prepare-release.sh @@ -26,7 +26,7 @@ python3 setup.py sdist bdist_wheel rm -rf ../py3-install-test-virtualenv virtualenv -p /usr/bin/python3 ../py3-install-test-virtualenv source ../py3-install-test-virtualenv/bin/activate -pip install dist/beautifulsoup4-*.whl lxml html5lib +pip install dist/beautifulsoup4-*.whl pytest lxml html5lib soupsieve pytest ../py3-install-test-virtualenv/lib/python3.8/site-packages/bs4/tests/ echo "EXPECT HTML ON LINE BELOW" (cd .. && python -c "from bs4 import _s; print(_s('<a>foo', 'html.parser'))") |