changeset 34723:b13c95919ff5

templater: explode if we try to emit a str Without this if branch, we infinitely recurse in _flatten, which is very confusing. Something in an hgweb template is trying to write out a string instead of a bytes on Python 3, and this at least makes it crash politely. Differential Revision: https://phab.mercurial-scm.org/D1088
author Augie Fackler <augie@google.com>
date Sat, 14 Oct 2017 11:30:17 -0400
parents 95be8928d6b2
children 9c3dcaf648ef
files mercurial/templater.py
diffstat 1 files changed, 5 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/templater.py	Sat Oct 14 11:20:31 2017 -0400
+++ b/mercurial/templater.py	Sat Oct 14 11:30:17 2017 -0400
@@ -1240,6 +1240,11 @@
     thing = templatekw.unwraphybrid(thing)
     if isinstance(thing, bytes):
         yield thing
+    elif isinstance(thing, str):
+        # We can only hit this on Python 3, and it's here to guard
+        # against infinite recursion.
+        raise error.ProgrammingError('Mercurial IO including templates is done'
+                                     ' with bytes, not strings')
     elif thing is None:
         pass
     elif not util.safehasattr(thing, '__iter__'):