Mercurial > public > mercurial-scm > hg
comparison mercurial/changelog.py @ 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 | 7e295dd10d40 |
children | aa6821a7b52f |
comparison
equal
deleted
inserted
replaced
15658:971c55ce03b8 | 15661:20ae902c43ec |
---|---|
22 # subset of the string_escape codec | 22 # subset of the string_escape codec |
23 text = text.replace('\\', '\\\\').replace('\n', '\\n').replace('\r', '\\r') | 23 text = text.replace('\\', '\\\\').replace('\n', '\\n').replace('\r', '\\r') |
24 return text.replace('\0', '\\0') | 24 return text.replace('\0', '\\0') |
25 | 25 |
26 def decodeextra(text): | 26 def decodeextra(text): |
27 """ | |
28 >>> decodeextra(encodeextra({'foo': 'bar', 'baz': chr(0) + '2'})) | |
29 {'foo': 'bar', 'baz': '\\x002'} | |
30 >>> decodeextra(encodeextra({'foo': 'bar', 'baz': chr(92) + chr(0) + '2'})) | |
31 {'foo': 'bar', 'baz': '\\\\\\x002'} | |
32 """ | |
27 extra = {} | 33 extra = {} |
28 for l in text.split('\0'): | 34 for l in text.split('\0'): |
29 if l: | 35 if l: |
36 if '\\0' in l: | |
37 # fix up \0 without getting into trouble with \\0 | |
38 l = l.replace('\\\\', '\\\\\n') | |
39 l = l.replace('\\0', '\0') | |
40 l = l.replace('\n', '') | |
30 k, v = l.decode('string_escape').split(':', 1) | 41 k, v = l.decode('string_escape').split(':', 1) |
31 extra[k] = v | 42 extra[k] = v |
32 return extra | 43 return extra |
33 | 44 |
34 def encodeextra(d): | 45 def encodeextra(d): |