Skip to content

Commit

Permalink
re.escape() arguments for 'contains()' (#2446)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Apr 7, 2022
1 parent 78e5d0c commit d78a2c7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gallery_dl/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def contains(values, elements):
if isinstance(values, str):
fmt = r"\b{}\b".format
for e in elements:
if re.search(fmt(e), values):
if re.compile(fmt(re.escape(e))).search(values):
return True
else:
for e in elements:
Expand Down
5 changes: 2 additions & 3 deletions test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,8 @@ def test_contains(self):
self.assertFalse(util.contains(c, "bar"))
self.assertFalse(util.contains(c, [2, 5, "bar"]))

s = "1, 2, 3, asd, qwe, yxc, foo, bar"
self.assertTrue(util.contains(s, 2))
self.assertTrue(util.contains(s, "asd"))
s = "1, 2, 3, asd, qwe, y(+)c, f(+)(-), bar"
self.assertTrue(util.contains(s, "y(+)c"))
self.assertTrue(util.contains(s, ["asd", "qwe", "yxc"]))
self.assertTrue(util.contains(s, ["sdf", "dfg", "qwe"]))
self.assertFalse(util.contains(s, "tag1"))
Expand Down

0 comments on commit d78a2c7

Please sign in to comment.