# HG changeset patch # User Matt Mackall # Date 1324081395 21600 # Node ID 20ae902c43ec5560868b1321c9f156a8c33ef53d # Parent 971c55ce03b81cc71ea33342bc432cc359e79e2a 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. diff -r 971c55ce03b8 -r 20ae902c43ec mercurial/changelog.py --- 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