Unverified Commit 7f42d6d0 authored by Paul Yang's avatar Paul Yang Committed by GitHub

Fix empty FieldMask json encoding/decoding (#5605)

* Fix empty FieldMask json encoding/decoding

* Add failed test to python's conformance failure list
parent 1069565a
...@@ -2042,6 +2042,10 @@ void BinaryAndJsonConformanceSuite::RunSuiteImpl() { ...@@ -2042,6 +2042,10 @@ void BinaryAndJsonConformanceSuite::RunSuiteImpl() {
"FieldMask", REQUIRED, "FieldMask", REQUIRED,
R"({"optionalFieldMask": "foo,barBaz"})", R"({"optionalFieldMask": "foo,barBaz"})",
R"(optional_field_mask: {paths: "foo" paths: "bar_baz"})"); R"(optional_field_mask: {paths: "foo" paths: "bar_baz"})");
RunValidJsonTest(
"EmptyFieldMask", REQUIRED,
R"({"optionalFieldMask": ""})",
R"(optional_field_mask: {})");
ExpectParseFailureForJson( ExpectParseFailureForJson(
"FieldMaskInvalidCharacter", RECOMMENDED, "FieldMaskInvalidCharacter", RECOMMENDED,
R"({"optionalFieldMask": "foo,bar_bar"})"); R"({"optionalFieldMask": "foo,bar_bar"})");
......
...@@ -19,3 +19,4 @@ Required.Proto3.ProtobufInput.IllegalZeroFieldNum_Case_0 ...@@ -19,3 +19,4 @@ Required.Proto3.ProtobufInput.IllegalZeroFieldNum_Case_0
Required.Proto3.ProtobufInput.IllegalZeroFieldNum_Case_1 Required.Proto3.ProtobufInput.IllegalZeroFieldNum_Case_1
Required.Proto3.ProtobufInput.IllegalZeroFieldNum_Case_2 Required.Proto3.ProtobufInput.IllegalZeroFieldNum_Case_2
Required.Proto3.ProtobufInput.IllegalZeroFieldNum_Case_3 Required.Proto3.ProtobufInput.IllegalZeroFieldNum_Case_3
Required.Proto3.JsonInput.EmptyFieldMask.ProtobufOutput
...@@ -20,3 +20,4 @@ Required.Proto3.JsonInput.FloatFieldTooLarge ...@@ -20,3 +20,4 @@ Required.Proto3.JsonInput.FloatFieldTooLarge
Required.Proto3.JsonInput.FloatFieldTooSmall Required.Proto3.JsonInput.FloatFieldTooSmall
Required.Proto3.JsonInput.RepeatedFieldWrongElementTypeExpectingIntegersGotBool Required.Proto3.JsonInput.RepeatedFieldWrongElementTypeExpectingIntegersGotBool
Required.Proto3.JsonInput.TimestampJsonInputLowercaseT Required.Proto3.JsonInput.TimestampJsonInputLowercaseT
Required.Proto3.JsonInput.EmptyFieldMask.ProtobufOutput
This diff is collapsed.
...@@ -518,8 +518,11 @@ class GPBUtil ...@@ -518,8 +518,11 @@ class GPBUtil
public static function parseFieldMask($paths_string) public static function parseFieldMask($paths_string)
{ {
$path_strings = explode(",", $paths_string);
$field_mask = new FieldMask(); $field_mask = new FieldMask();
if (strlen($paths_string) === 0) {
return $field_mask;
}
$path_strings = explode(",", $paths_string);
$paths = $field_mask->getPaths(); $paths = $field_mask->getPaths();
foreach($path_strings as &$path_string) { foreach($path_strings as &$path_string) {
$field_strings = explode(".", $path_string); $field_strings = explode(".", $path_string);
......
...@@ -1128,4 +1128,11 @@ class EncodeDecodeTest extends TestBase ...@@ -1128,4 +1128,11 @@ class EncodeDecodeTest extends TestBase
$this->assertSame("\"foo.barBaz,qux\"", $m->serializeToJsonString()); $this->assertSame("\"foo.barBaz,qux\"", $m->serializeToJsonString());
} }
public function testDecodeEmptyFieldMask()
{
$m = new FieldMask();
$m->mergeFromJsonString("\"\"");
$this->assertEquals("", $m->serializeToString());
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment