summaryrefslogtreecommitdiff
path: root/bs4/element.py
diff options
context:
space:
mode:
authorLeonard Richardson <leonardr@segfault.org>2016-07-18 22:23:22 -0400
committerLeonard Richardson <leonardr@segfault.org>2016-07-18 22:23:22 -0400
commitff95d577bfcec85cca29b6f7041a508db7d8d841 (patch)
tree2add1e78b349f7fcdcfca87a8993378e8728d02a /bs4/element.py
parent964a25828644e87daa80c2b85ceaed397bca637e (diff)
If a search against each individual value of a multi-valued
attribute fails, the search will be run one final time against the complete attribute value considered as a single string. [bug=1476868]
Diffstat (limited to 'bs4/element.py')
-rw-r--r--bs4/element.py24
1 files changed, 9 insertions, 15 deletions
diff --git a/bs4/element.py b/bs4/element.py
index ad13533..5a3665e 100644
--- a/bs4/element.py
+++ b/bs4/element.py
@@ -1704,21 +1704,15 @@ class SoupStrainer(object):
if isinstance(markup, list) or isinstance(markup, tuple):
# This should only happen when searching a multi-valued attribute
# like 'class'.
- if (isinstance(match_against, unicode)
- and ' ' in match_against):
- # A bit of a special case. If they try to match "foo
- # bar" on a multivalue attribute's value, only accept
- # the literal value "foo bar"
- #
- # XXX This is going to be pretty slow because we keep
- # splitting match_against. But it shouldn't come up
- # too often.
- return (whitespace_re.split(match_against) == markup)
- else:
- for item in markup:
- if self._matches(item, match_against):
- return True
- return False
+ for item in markup:
+ if self._matches(item, match_against):
+ return True
+ # We didn't match any particular value of the multivalue
+ # attribute, but maybe we match the attribute value when
+ # considered as a string.
+ if self._matches(' '.join(markup), match_against):
+ return True
+ return False
if match_against is True:
# True matches any non-None value.