changeset 26372:55de800937e0

formatter: verify number of arguments passed to write functions zip() takes the shortest length, which can be a source of bug.
author Yuya Nishihara <yuya@tcha.org>
date Wed, 23 Sep 2015 21:51:48 +0900
parents 51b309ce6c7d
children aa610ffad4e8
files mercurial/formatter.py
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/formatter.py	Sat Sep 26 11:50:47 2015 +0900
+++ b/mercurial/formatter.py	Wed Sep 23 21:51:48 2015 +0900
@@ -48,11 +48,15 @@
         self._item.update(data)
     def write(self, fields, deftext, *fielddata, **opts):
         '''do default text output while assigning data to item'''
-        for k, v in zip(fields.split(), fielddata):
+        fieldkeys = fields.split()
+        assert len(fieldkeys) == len(fielddata)
+        for k, v in zip(fieldkeys, fielddata):
             self._item[k] = v
     def condwrite(self, cond, fields, deftext, *fielddata, **opts):
         '''do conditional write (primarily for plain formatter)'''
-        for k, v in zip(fields.split(), fielddata):
+        fieldkeys = fields.split()
+        assert len(fieldkeys) == len(fielddata)
+        for k, v in zip(fieldkeys, fielddata):
             self._item[k] = v
     def plain(self, text, **opts):
         '''show raw text for non-templated mode'''