aboutsummaryrefslogtreecommitdiffhomepage
path: root/python/google/protobuf/text_format.py
diff options
context:
space:
mode:
authorGravatar xiaofeng@google.com <xiaofeng@google.com@630680e5-0e50-0410-840e-4b1c322b438d>2013-02-25 10:39:39 +0000
committerGravatar xiaofeng@google.com <xiaofeng@google.com@630680e5-0e50-0410-840e-4b1c322b438d>2013-02-25 10:39:39 +0000
commit7f372559cc31f15e8c30694ee7329bc0082454fe (patch)
tree43d43a78c1f8532ed2c729b60d98f73c24f0e0c1 /python/google/protobuf/text_format.py
parentde3494fe5cbfdb75631bd07877341d56d721730c (diff)
Down-integrate from internal branch
Diffstat (limited to 'python/google/protobuf/text_format.py')
-rwxr-xr-xpython/google/protobuf/text_format.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/python/google/protobuf/text_format.py b/python/google/protobuf/text_format.py
index 0714c39d..24dd07f2 100755
--- a/python/google/protobuf/text_format.py
+++ b/python/google/protobuf/text_format.py
@@ -608,12 +608,17 @@ def _CEscape(text, as_utf8):
return "".join([escape(c) for c in text])
-_CUNESCAPE_HEX = re.compile('\\\\x([0-9a-fA-F]{2}|[0-9a-fA-F])')
+_CUNESCAPE_HEX = re.compile(r'(\\+)x([0-9a-fA-F])(?![0-9a-fA-F])')
def _CUnescape(text):
def ReplaceHex(m):
- return chr(int(m.group(0)[2:], 16))
+ # Only replace the match if the number of leading back slashes is odd. i.e.
+ # the slash itself is not escaped.
+ if len(m.group(1)) & 1:
+ return m.group(1) + 'x0' + m.group(2)
+ return m.group(0)
+
# This is required because the 'string_escape' encoding doesn't
# allow single-digit hex escapes (like '\xf').
result = _CUNESCAPE_HEX.sub(ReplaceHex, text)