summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS.txt3
-rw-r--r--bs4/element.py3
-rw-r--r--bs4/tests/test_tree.py4
3 files changed, 6 insertions, 4 deletions
diff --git a/NEWS.txt b/NEWS.txt
index 1c3e19c..ea49586 100644
--- a/NEWS.txt
+++ b/NEWS.txt
@@ -1,5 +1,8 @@
= 4.0.0b6 () =
+* The value of multi-valued attributes like "class" are always turned
+ into a list, even if there's only one value.
+
* Passing text along with tag-specific arguments to a find* method:
find("a", text="Click here")
diff --git a/bs4/element.py b/bs4/element.py
index c6a7823..cf1ed32 100644
--- a/bs4/element.py
+++ b/bs4/element.py
@@ -535,8 +535,7 @@ class Tag(PageElement):
# classes. Split it into a list.
value = attrs[cdata_list_attr]
values = whitespace_re.split(value)
- if len(values) > 1:
- attrs[cdata_list_attr] = values
+ attrs[cdata_list_attr] = values
self.attrs = attrs
self.contents = []
self.setup(parent, previous)
diff --git a/bs4/tests/test_tree.py b/bs4/tests/test_tree.py
index 8e61429..3684777 100644
--- a/bs4/tests/test_tree.py
+++ b/bs4/tests/test_tree.py
@@ -1045,9 +1045,9 @@ class TestCDAtaListAttributes(SoupTest):
"""Testing cdata-list attributes like 'class'.
"""
- def test_single_value_stays_string(self):
+ def test_single_value_becomes_list(self):
soup = self.soup("<a class='foo'>")
- self.assertEqual("foo",soup.a['class'])
+ self.assertEqual(["foo"],soup.a['class'])
def test_multiple_values_becomes_list(self):
soup = self.soup("<a class='foo bar'>")