Commit d177a4bc authored by Benjamin Bouvier's avatar Benjamin Bouvier

Fixes #438: regexp filter: return default when the incoming txt value isn't a string

Signed-off-by: Benjamin Bouvier's avatarBenjamin Bouvier <public@benj.me>
parent 865cbfea
Pipeline #3395 passed with stages
in 14 minutes and 34 seconds
......@@ -595,8 +595,14 @@ class Regexp(Filter):
if isinstance(txt, (tuple, list)):
txt = u' '.join([t.strip() for t in txt.itertext()])
m = self._regex.search(txt) if self.nth == 0 else \
nth(self._regex.finditer(txt), self.nth)
m = None
try:
m = self._regex.search(txt) if self.nth == 0 else \
nth(self._regex.finditer(txt), self.nth)
except TypeError:
msg = '%r is not a string or bytes-like object' % txt
return self.default_or_raise(RegexpError(msg))
if not m:
msg = 'Unable to find %s %s in %r' % (ordinal(self.nth), self.pattern, txt)
return self.default_or_raise(RegexpError(msg))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment