diff options
author | Leonard Richardson <leonardr@segfault.org> | 2012-05-24 10:49:48 -0400 |
---|---|---|
committer | Leonard Richardson <leonardr@segfault.org> | 2012-05-24 10:49:48 -0400 |
commit | 44a7d024d824ccf557f67c81503131f824e3b109 (patch) | |
tree | e3dec9f186700293adf90da5b33ef904cf7f1e73 /bs4/element.py | |
parent | 6ec38efd97e9deb8fb362890f670ba9571f60e10 (diff) |
Fixed the basic failure in [bug=1003974], but not more advanced cases.
Diffstat (limited to 'bs4/element.py')
-rw-r--r-- | bs4/element.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/bs4/element.py b/bs4/element.py index 99a3540..6fb89ea 100644 --- a/bs4/element.py +++ b/bs4/element.py @@ -1287,15 +1287,24 @@ class SoupStrainer(object): result = markup and match_against.search(markup) elif (hasattr(match_against, '__iter__') and markup is not None - and not isinstance(match_against, basestring)): + and not isinstance(match_against, bytes) + and not isinstance(match_against, unicode)): result = markup in match_against elif hasattr(match_against, 'items'): if markup is None: result = len(match_against.items()) == 0 else: result = match_against in markup - elif match_against and isinstance(markup, basestring): - match_against = markup.__class__(match_against) + elif match_against is not None: + if isinstance(match_against, unicode): + # Unicode is fine. + pass + elif isinstance(match_against, bytes): + # A bytestring should be converted into Unicode. + match_against = match_against.decode("utf8") + else: + # Anything else should be converted into a string, then to Unicode. + match_against = str(match_against) if not result: result = match_against == markup |