diff options
author | Josh Haberman <jhaberman@gmail.com> | 2016-05-17 18:07:39 -0700 |
---|---|---|
committer | Josh Haberman <jhaberman@gmail.com> | 2016-06-03 09:39:38 -0700 |
commit | bd98eae1c944e453784cdf96c05cc40de55a9690 (patch) | |
tree | 7698c6534763424ffbcb86f84bfeebdadc8d2d0d /python/google | |
parent | ef7894e2dc6d287419e42a4fdc52cdfedd386d16 (diff) | |
download | protobuf-bd98eae1c944e453784cdf96c05cc40de55a9690.tar.gz protobuf-bd98eae1c944e453784cdf96c05cc40de55a9690.tar.bz2 protobuf-bd98eae1c944e453784cdf96c05cc40de55a9690.zip |
Fixed Python by updating failure lists and fixed a few broken tests.
Python 2.x doesn't detect unpaired surrogates so we have to
do that manually.
Diffstat (limited to 'python/google')
-rw-r--r-- | python/google/protobuf/json_format.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/python/google/protobuf/json_format.py b/python/google/protobuf/json_format.py index 57aa4077..8af6cd20 100644 --- a/python/google/protobuf/json_format.py +++ b/python/google/protobuf/json_format.py @@ -49,6 +49,7 @@ except ImportError: import base64 import json import math +import re import six import sys @@ -68,6 +69,10 @@ _INFINITY = 'Infinity' _NEG_INFINITY = '-Infinity' _NAN = 'NaN' +if sys.version_info < (3, 0): + _UNPAIRED_SURROGATE_PATTERN = re.compile(six.u( + r'[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]' + )) class Error(Exception): """Top-level module error for json_format.""" @@ -554,6 +559,11 @@ def _ConvertScalarFieldValue(value, field, require_str=False): elif field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_STRING: if field.type == descriptor.FieldDescriptor.TYPE_BYTES: return base64.b64decode(value) + elif sys.version_info < (3, 0): + # Python 2.x does not detect unpaired surrogates when JSON parsing. + if _UNPAIRED_SURROGATE_PATTERN.search(value): + raise ParseError('Unpaired surrogate') + return value else: return value elif field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_ENUM: |