summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS.txt5
-rw-r--r--bs4/element.py4
-rw-r--r--bs4/tests/test_tree.py12
3 files changed, 19 insertions, 2 deletions
diff --git a/NEWS.txt b/NEWS.txt
index dc790dc..097ee43 100644
--- a/NEWS.txt
+++ b/NEWS.txt
@@ -1,3 +1,8 @@
+= 4.0.2 () =
+
+* Fixed a bug where specifying `text` while searching for a tag only
+ worked if `text` specified an exact string match. [bug=955942]
+
= 4.0.1 (20120314) =
* This is the first official release of Beautiful Soup 4. There is no
diff --git a/bs4/element.py b/bs4/element.py
index d2fa19f..4ff9cd4 100644
--- a/bs4/element.py
+++ b/bs4/element.py
@@ -1156,7 +1156,7 @@ class SoupStrainer(object):
found = markup
else:
found = markup_name
- if found and self.text and self.text != found.string:
+ if found and self.text and not self._matches(found.string, self.text):
found = None
return found
searchTag = search_tag
@@ -1188,7 +1188,7 @@ class SoupStrainer(object):
return found
def _matches(self, markup, match_against):
- # print "Matching %s against %s" % (markup, match_against)
+ #print "Matching %s against %s" % (markup, match_against)
result = False
if isinstance(markup, list) or isinstance(markup, tuple):
diff --git a/bs4/tests/test_tree.py b/bs4/tests/test_tree.py
index e9a5763..4d114b7 100644
--- a/bs4/tests/test_tree.py
+++ b/bs4/tests/test_tree.py
@@ -126,6 +126,18 @@ class TestFindAllByName(TreeTest):
self.assertSelects(
self.tree.find_all('a'), ['First tag.', 'Nested tag.'])
+ def test_find_all_by_name_and_text(self):
+ self.assertSelects(
+ self.tree.find_all('a', text='First tag.'), ['First tag.'])
+
+ self.assertSelects(
+ self.tree.find_all('a', text=True), ['First tag.', 'Nested tag.'])
+
+ self.assertSelects(
+ self.tree.find_all('a', text=re.compile("tag")),
+ ['First tag.', 'Nested tag.'])
+
+
def test_find_all_on_non_root_element(self):
# You can call find_all on any node, not just the root.
self.assertSelects(self.tree.c.find_all('a'), ['Nested tag.'])