Mercurial > hg
comparison 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 |
comparison
equal
deleted
inserted
replaced
34658:dbe1f5118864 | 34659:3edfd472f3cb |
---|---|
795 if not (3 <= len(args) <= 4): | 795 if not (3 <= len(args) <= 4): |
796 # i18n: "ifcontains" is a keyword | 796 # i18n: "ifcontains" is a keyword |
797 raise error.ParseError(_("ifcontains expects three or four arguments")) | 797 raise error.ParseError(_("ifcontains expects three or four arguments")) |
798 | 798 |
799 haystack = evalfuncarg(context, mapping, args[1]) | 799 haystack = evalfuncarg(context, mapping, args[1]) |
800 needle = evalastype(context, mapping, args[0], | 800 try: |
801 getattr(haystack, 'keytype', None) or bytes) | 801 needle = evalastype(context, mapping, args[0], |
802 | 802 getattr(haystack, 'keytype', None) or bytes) |
803 if needle in haystack: | 803 found = (needle in haystack) |
804 except error.ParseError: | |
805 found = False | |
806 | |
807 if found: | |
804 yield evalrawexp(context, mapping, args[2]) | 808 yield evalrawexp(context, mapping, args[2]) |
805 elif len(args) == 4: | 809 elif len(args) == 4: |
806 yield evalrawexp(context, mapping, args[3]) | 810 yield evalrawexp(context, mapping, args[3]) |
807 | 811 |
808 @templatefunc('ifeq(expr1, expr2, then[, else])') | 812 @templatefunc('ifeq(expr1, expr2, then[, else])') |