Mercurial > public > mercurial-scm > hg
comparison mercurial/templatefilters.py @ 23708:a9f826c3eaf9
templatefilters.json: stabilize output
The json filter was previously iterating over keys in an object in an
undefined order. Let's throw a sorted() in there so output is
consistent.
It's somewhat frightening that there are no tests for the json filter.
Subsequent commits will add them, so we pass on the opportunity to add
them here.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Wed, 31 Dec 2014 13:48:55 -0800 |
parents | ae5447de4c11 |
children | 6abce80e6cbf |
comparison
equal
deleted
inserted
replaced
23707:ae5447de4c11 | 23708:a9f826c3eaf9 |
---|---|
197 return '"%s"' % jsonescape(u) | 197 return '"%s"' % jsonescape(u) |
198 elif isinstance(obj, unicode): | 198 elif isinstance(obj, unicode): |
199 return '"%s"' % jsonescape(obj) | 199 return '"%s"' % jsonescape(obj) |
200 elif util.safehasattr(obj, 'keys'): | 200 elif util.safehasattr(obj, 'keys'): |
201 out = [] | 201 out = [] |
202 for k, v in obj.iteritems(): | 202 for k, v in sorted(obj.iteritems()): |
203 s = '%s: %s' % (json(k), json(v)) | 203 s = '%s: %s' % (json(k), json(v)) |
204 out.append(s) | 204 out.append(s) |
205 return '{' + ', '.join(out) + '}' | 205 return '{' + ', '.join(out) + '}' |
206 elif util.safehasattr(obj, '__iter__'): | 206 elif util.safehasattr(obj, '__iter__'): |
207 out = [] | 207 out = [] |