formatter: verify number of arguments passed to write functions
authorYuya Nishihara <yuya@tcha.org>
Wed, 23 Sep 2015 21:51:48 +0900
changeset 26372 55de800937e0
parent 26371 51b309ce6c7d
child 26373 aa610ffad4e8
formatter: verify number of arguments passed to write functions zip() takes the shortest length, which can be a source of bug.
mercurial/formatter.py
--- 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'''