[PATCH] changelog: fix decoding of extra data (issue3156)
Lars Boehnke
lboehnke at symmetricom.com
Fri Dec 16 18:26:04 UTC 2011
# HG changeset patch
# User lboehnke <lboehnke at symmetricom.com>
# Date 1324058856 25200
# Node ID 56a4a7dd2adc50e4db9486b5b90c4b1a5fb06ccd
# Parent c7b0bedbb07ac3752243db046f54c9a4bbc3273d
changelog: fix decoding of extra data (issue3156)
The 'string_escape' codec is not compatible with the custom
encoding used in _string_escape. This adds a custom decoder that
is compatible.
diff -r c7b0bedbb07a -r 56a4a7dd2adc mercurial/changelog.py
--- a/mercurial/changelog.py Thu Dec 15 16:50:21 2011 -0600
+++ b/mercurial/changelog.py Fri Dec 16 11:07:36 2011 -0700
@@ -23,11 +23,43 @@
text = text.replace('\\', '\\\\').replace('\n', '\\n').replace('\r', '\\r')
return text.replace('\0', '\\0')
+def _string_unescape(text):
+ result = ""
+ char = None
+ inescape = False
+ for x in text:
+ if inescape is False and x == '\\':
+ inescape = True
+ continue
+
+ if inescape:
+ if x == '\\':
+ char = '\\'
+ elif x == 'n':
+ char = '\n'
+ elif x == 'r':
+ char = '\r'
+ elif x == '0':
+ char = '\x00'
+ else:
+ raise error.RevlogError(_("bad escaped character: '%s'")%x)
+ inescape = False
+ else:
+ char = x
+
+ result += char
+
+ # defensive - make sure we did not end in an escape sequence
+ if inescape:
+ raise error.RevlogError(_("ended in escape sequence"))
+ return result
+
+
def decodeextra(text):
extra = {}
for l in text.split('\0'):
if l:
- k, v = l.decode('string_escape').split(':', 1)
+ k, v = _string_unescape(l).split(':', 1)
extra[k] = v
return extra
More information about the Mercurial-devel
mailing list