Mercurial > hg
changeset 36573:9b6b02a5b589
templatefilters: avoid infinite recursion bug in stringify
This doesn't ever happen on Python 2, but it's been a persistent pain
on Python 3. Adding this helped produce some of my upcoming Python 3
fixes.
Differential Revision: https://phab.mercurial-scm.org/D2553
author | Augie Fackler <augie@google.com> |
---|---|
date | Fri, 02 Mar 2018 09:08:11 -0500 |
parents | 9adfa48792a7 |
children | 45f149bf08d1 |
files | mercurial/templatefilters.py |
diffstat | 1 files changed, 6 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/templatefilters.py Fri Mar 02 00:37:55 2018 -0500 +++ b/mercurial/templatefilters.py Fri Mar 02 09:08:11 2018 -0500 @@ -376,6 +376,12 @@ """ thing = templatekw.unwraphybrid(thing) if util.safehasattr(thing, '__iter__') and not isinstance(thing, bytes): + if isinstance(thing, str): + # This is only reachable on Python 3 (otherwise + # isinstance(thing, bytes) would have been true), and is + # here to prevent infinite recursion bugs on Python 3. + raise error.ProgrammingError( + 'stringify got unexpected unicode string: %r' % thing) return "".join([stringify(t) for t in thing if t is not None]) if thing is None: return ""