Mercurial > hg
changeset 15661:20ae902c43ec stable
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.
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Fri, 16 Dec 2011 18:23:15 -0600 |
parents | 971c55ce03b8 |
children | 06671371e634 |
files | mercurial/changelog.py |
diffstat | 1 files changed, 11 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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