From b9cfa0330bf4c6017d89ab66dcf33dac925e7044 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Sat, 28 Jul 2018 18:23:00 -0400 Subject: When markup contains duplicate elements, a select() call that includes multiple match clauses will match all relevant elements. [bug=1770596] --- bs4/tests/test_tree.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'bs4/tests/test_tree.py') diff --git a/bs4/tests/test_tree.py b/bs4/tests/test_tree.py index e5dcfa7..68887b4 100644 --- a/bs4/tests/test_tree.py +++ b/bs4/tests/test_tree.py @@ -2074,5 +2074,17 @@ class TestSoupSelector(TreeTest): def test_multiple_select_nested(self): self.assertSelects('body > div > x, y > z', ['xid', 'zidb']) - + def test_select_duplicate_elements(self): + # When markup contains duplicate elements, a multiple select + # will find all of them. + markup = '
' + soup = BeautifulSoup(markup, 'html.parser') + selected = soup.select(".c1, .c2") + self.assertEquals(3, len(selected)) + + # Verify that find_all finds the same elements, though because + # of an implementation detail it finds them in a different + # order. + for element in soup.find_all(class_=['c1', 'c2']): + assert element in selected -- cgit v1.2.3