Fix empty FieldMask json encoding/decoding (#5605)

* Fix empty FieldMask json encoding/decoding

* Add failed test to python's conformance failure list
This commit is contained in:
Paul Yang 2019-01-22 15:35:12 -08:00 committed by GitHub
parent 1069565a68
commit 7f42d6d0bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 317 additions and 877 deletions

View File

@ -2042,6 +2042,10 @@ void BinaryAndJsonConformanceSuite::RunSuiteImpl() {
"FieldMask", REQUIRED,
R"({"optionalFieldMask": "foo,barBaz"})",
R"(optional_field_mask: {paths: "foo" paths: "bar_baz"})");
RunValidJsonTest(
"EmptyFieldMask", REQUIRED,
R"({"optionalFieldMask": ""})",
R"(optional_field_mask: {})");
ExpectParseFailureForJson(
"FieldMaskInvalidCharacter", RECOMMENDED,
R"({"optionalFieldMask": "foo,bar_bar"})");

View File

@ -19,3 +19,4 @@ Required.Proto3.ProtobufInput.IllegalZeroFieldNum_Case_0
Required.Proto3.ProtobufInput.IllegalZeroFieldNum_Case_1
Required.Proto3.ProtobufInput.IllegalZeroFieldNum_Case_2
Required.Proto3.ProtobufInput.IllegalZeroFieldNum_Case_3
Required.Proto3.JsonInput.EmptyFieldMask.ProtobufOutput

View File

@ -20,3 +20,4 @@ Required.Proto3.JsonInput.FloatFieldTooLarge
Required.Proto3.JsonInput.FloatFieldTooSmall
Required.Proto3.JsonInput.RepeatedFieldWrongElementTypeExpectingIntegersGotBool
Required.Proto3.JsonInput.TimestampJsonInputLowercaseT
Required.Proto3.JsonInput.EmptyFieldMask.ProtobufOutput

File diff suppressed because it is too large Load Diff

View File

@ -518,8 +518,11 @@ class GPBUtil
public static function parseFieldMask($paths_string)
{
$path_strings = explode(",", $paths_string);
$field_mask = new FieldMask();
if (strlen($paths_string) === 0) {
return $field_mask;
}
$path_strings = explode(",", $paths_string);
$paths = $field_mask->getPaths();
foreach($path_strings as &$path_string) {
$field_strings = explode(".", $path_string);

View File

@ -1128,4 +1128,11 @@ class EncodeDecodeTest extends TestBase
$this->assertSame("\"foo.barBaz,qux\"", $m->serializeToJsonString());
}
public function testDecodeEmptyFieldMask()
{
$m = new FieldMask();
$m->mergeFromJsonString("\"\"");
$this->assertEquals("", $m->serializeToString());
}
}