diff options
author | Josh Haberman <jhaberman@gmail.com> | 2016-06-03 10:24:23 -0700 |
---|---|---|
committer | Josh Haberman <jhaberman@gmail.com> | 2016-06-03 10:24:23 -0700 |
commit | 6a618949aa639b7007d0fce16f9a7c856488cd18 (patch) | |
tree | 9bde414231724217d09b5333bdb0b32869dc0c1a /python | |
parent | 84a1b607037329c736a0e79fb5e6d64114d9ced3 (diff) | |
download | protobuf-6a618949aa639b7007d0fce16f9a7c856488cd18.tar.gz protobuf-6a618949aa639b7007d0fce16f9a7c856488cd18.tar.bz2 protobuf-6a618949aa639b7007d0fce16f9a7c856488cd18.zip |
Added test for surrogates (valid and invalid).
Diffstat (limited to 'python')
-rw-r--r-- | python/google/protobuf/internal/json_format_test.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/python/google/protobuf/internal/json_format_test.py b/python/google/protobuf/internal/json_format_test.py index eec1f56f..ba73c68c 100644 --- a/python/google/protobuf/internal/json_format_test.py +++ b/python/google/protobuf/internal/json_format_test.py @@ -247,6 +247,27 @@ class JsonFormatTest(JsonFormatBase): parsed_message = json_format_proto3_pb2.TestOneof() self.CheckParseBack(message, parsed_message) + def testSurrogates(self): + # Test correct surrogate handling. + message = json_format_proto3_pb2.TestMessage() + json_format.Parse('{"stringValue": "\\uD83D\\uDE01"}', message) + self.assertEqual(message.string_value, + b'\xF0\x9F\x98\x81'.decode("utf-8", "strict")) + + # TODO: add test that UTF-8 encoded surrogate code points are rejected. + # UTF-8 does not allow them. + + # Error case: unpaired high surrogate. + self.CheckError( + '{"stringValue": "\\uD83D"}', + r'Invalid \\uXXXX escape|Unpaired surrogate') + + # Unpaired low surrogate. + self.CheckError( + '{"stringValue": "\\uDE01"}', + r'Invalid \\uXXXX escape|Unpaired surrogate') + + def testTimestampMessage(self): message = json_format_proto3_pb2.TestTimestamp() message.value.seconds = 0 |