diff options
author | Leonard Richardson <leonard.richardson@canonical.com> | 2012-02-15 14:44:05 -0500 |
---|---|---|
committer | Leonard Richardson <leonard.richardson@canonical.com> | 2012-02-15 14:44:05 -0500 |
commit | ac197c5ad0ffe0795436cb54e0766640d12c6a31 (patch) | |
tree | 23938b1e3f83692d893bb966b5470e78f1f28dd3 | |
parent | a06152365c336f41bdb5fb9513b9316740c1564a (diff) |
The value of multi-valued attributes like class are always turned into a list, even if there's only one value.
-rw-r--r-- | NEWS.txt | 3 | ||||
-rw-r--r-- | bs4/element.py | 3 | ||||
-rw-r--r-- | bs4/tests/test_tree.py | 4 |
3 files changed, 6 insertions, 4 deletions
@@ -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'>") |