changelog: handle decoding of NULs in extra more carefully (issue3156)
Escaped NULs adjacent to [0-7] could be decoded as octal. This hits
about 0.24% of changesets with transplant, which stores binary nodes.
--- a/mercurial/changelog.py Thu Dec 15 13:19:43 2011 -0500
+++ b/mercurial/changelog.py Fri Dec 16 18:23:15 2011 -0600
@@ -24,9 +24,20 @@
return text.replace('\0', '\\0')
def decodeextra(text):
+ """
+ >>> decodeextra(encodeextra({'foo': 'bar', 'baz': chr(0) + '2'}))
+ {'foo': 'bar', 'baz': '\\x002'}
+ >>> decodeextra(encodeextra({'foo': 'bar', 'baz': chr(92) + chr(0) + '2'}))
+ {'foo': 'bar', 'baz': '\\\\\\x002'}
+ """
extra = {}
for l in text.split('\0'):
if l:
+ if '\\0' in l:
+ # fix up \0 without getting into trouble with \\0
+ l = l.replace('\\\\', '\\\\\n')
+ l = l.replace('\\0', '\0')
+ l = l.replace('\n', '')
k, v = l.decode('string_escape').split(':', 1)
extra[k] = v
return extra