diff options
author | Josh Haberman <jhaberman@gmail.com> | 2016-05-24 07:57:30 -0700 |
---|---|---|
committer | Josh Haberman <jhaberman@gmail.com> | 2016-06-03 09:39:38 -0700 |
commit | 4833b4c003651ff11827cb1a23ec842c4de2ebb5 (patch) | |
tree | f36996a920c1256c5a8d4ddb71872416336ddce8 | |
parent | bd98eae1c944e453784cdf96c05cc40de55a9690 (diff) | |
download | protobuf-4833b4c003651ff11827cb1a23ec842c4de2ebb5.tar.gz protobuf-4833b4c003651ff11827cb1a23ec842c4de2ebb5.tar.bz2 protobuf-4833b4c003651ff11827cb1a23ec842c4de2ebb5.zip |
Surrogate checking is unpredictable, so always manually check.
-rw-r--r-- | conformance/failure_list_python.txt | 16 | ||||
-rw-r--r-- | python/google/protobuf/json_format.py | 14 |
2 files changed, 6 insertions, 24 deletions
diff --git a/conformance/failure_list_python.txt b/conformance/failure_list_python.txt index ab7fc031..550a043f 100644 --- a/conformance/failure_list_python.txt +++ b/conformance/failure_list_python.txt @@ -43,21 +43,5 @@ JsonInput.Uint32FieldMaxFloatValue.JsonOutput JsonInput.Uint32FieldMaxFloatValue.ProtobufOutput JsonInput.ValueAcceptNull.JsonOutput JsonInput.ValueAcceptNull.ProtobufOutput -ProtobufInput.PrematureEofInDelimitedDataForKnownNonRepeatedValue.MESSAGE -ProtobufInput.PrematureEofInDelimitedDataForKnownRepeatedValue.MESSAGE -ProtobufInput.PrematureEofInPackedField.BOOL -ProtobufInput.PrematureEofInPackedField.DOUBLE -ProtobufInput.PrematureEofInPackedField.ENUM -ProtobufInput.PrematureEofInPackedField.FIXED32 -ProtobufInput.PrematureEofInPackedField.FIXED64 -ProtobufInput.PrematureEofInPackedField.FLOAT -ProtobufInput.PrematureEofInPackedField.INT32 -ProtobufInput.PrematureEofInPackedField.INT64 -ProtobufInput.PrematureEofInPackedField.SFIXED32 -ProtobufInput.PrematureEofInPackedField.SFIXED64 -ProtobufInput.PrematureEofInPackedField.SINT32 -ProtobufInput.PrematureEofInPackedField.SINT64 -ProtobufInput.PrematureEofInPackedField.UINT32 -ProtobufInput.PrematureEofInPackedField.UINT64 TimestampProtoInputTooLarge.JsonOutput TimestampProtoInputTooSmall.JsonOutput diff --git a/python/google/protobuf/json_format.py b/python/google/protobuf/json_format.py index 8af6cd20..be6a9b63 100644 --- a/python/google/protobuf/json_format.py +++ b/python/google/protobuf/json_format.py @@ -69,10 +69,9 @@ _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]' - )) +_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.""" @@ -559,13 +558,12 @@ 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. + else: + # Checking for unpaired surrogates appears to be unreliable, + # depending on the specific Python version, so we check manually. if _UNPAIRED_SURROGATE_PATTERN.search(value): raise ParseError('Unpaired surrogate') return value - else: - return value elif field.cpp_type == descriptor.FieldDescriptor.CPPTYPE_ENUM: # Convert an enum value. enum_value = field.enum_type.values_by_name.get(value, None) |