D1088: templater: explode if we try to emit a str

durin42 (Augie Fackler) phabricator at mercurial-scm.org
Sun Oct 15 04:58:01 UTC 2017


durin42 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  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.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D1088

AFFECTED FILES
  mercurial/templater.py

CHANGE DETAILS

diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -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__'):



To: durin42, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list