Fix empty FieldMask json encoding/decoding (#5605)

* Fix empty FieldMask json encoding/decoding

* Add failed test to python's conformance failure list
pull/5616/head
Paul Yang 6 years ago committed by GitHub
parent 1069565a68
commit 7f42d6d0bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      conformance/binary_json_conformance_suite.cc
  2. 1
      conformance/failure_list_python.txt
  3. 1
      conformance/failure_list_python_cpp.txt
  4. 1178
      php/ext/google/protobuf/upb.c
  5. 5
      php/src/Google/Protobuf/Internal/GPBUtil.php
  6. 7
      php/tests/encode_decode_test.php

@ -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"})");

@ -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

@ -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

@ -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);

@ -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());
}
}

Loading…
Cancel
Save