Matching an attribute against [] does not work as expected
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Beautiful Soup |
Fix Committed
|
Undecided
|
Unassigned |
Bug Description
Let's say I have the following HTML document, where only <c> has an ID attribute:
>>> from bs4 import BeautifulSoup
>>> soup = BeautifulSoup(
If I match @id against None, it returns all tags with the attribute *undefined*:
>>> soup.find_all(id = None)
[<html>
If I match @id against [], again it returns all tags with the attribute *undefined*:
>>> soup.find_all(id = [])
[<html>
But my expectation is that it would return all tags with an @id value *defined* that matches a value in the list, which is no tags.
Attribute matches against lists and Booleans have different conventions. We should interpret an empty list using the list convention, not the Boolean convention.
This is already in the 4.13 branch. I fixed the bug without knowing about it, as a side effect of refactoring SoupStrainer. I added a unit test in revision ce2ba56.