Mercurial > public > mercurial-scm > hg-stable
diff mercurial/templater.py @ 34659:3edfd472f3cb
templater: fix ifcontains() to handle type mismatch gracefully
This was unintentionally changed in ee0d74083a22. Since ifcontains() takes
needle of any types, it shouldn't abort depending on the given container type.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Thu, 12 Oct 2017 22:09:11 +0900 |
parents | ee0d74083a22 |
children | 56bb07a0b75c |
line wrap: on
line diff
--- a/mercurial/templater.py Thu Oct 12 21:56:13 2017 +0900 +++ b/mercurial/templater.py Thu Oct 12 22:09:11 2017 +0900 @@ -797,10 +797,14 @@ raise error.ParseError(_("ifcontains expects three or four arguments")) haystack = evalfuncarg(context, mapping, args[1]) - needle = evalastype(context, mapping, args[0], - getattr(haystack, 'keytype', None) or bytes) + try: + needle = evalastype(context, mapping, args[0], + getattr(haystack, 'keytype', None) or bytes) + found = (needle in haystack) + except error.ParseError: + found = False - if needle in haystack: + if found: yield evalrawexp(context, mapping, args[2]) elif len(args) == 4: yield evalrawexp(context, mapping, args[3])