diff --git a/conformance/failure_list_php.txt b/conformance/failure_list_php.txt index 0d2341127ec31..8bd8a99ea4e70 100644 --- a/conformance/failure_list_php.txt +++ b/conformance/failure_list_php.txt @@ -13,6 +13,8 @@ Required.Proto3.JsonInput.FloatFieldTooSmall Required.Proto3.JsonInput.DoubleFieldTooSmall Required.Proto3.JsonInput.Int32FieldNotInteger Required.Proto3.JsonInput.Int64FieldNotInteger +Required.Proto3.JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotInt +Required.Proto3.JsonInput.StringFieldNotAString Required.Proto3.JsonInput.Uint32FieldNotInteger Required.Proto3.JsonInput.Uint64FieldNotInteger Required.Proto3.JsonInput.Int32FieldLeadingSpace diff --git a/php/src/Google/Protobuf/Internal/Message.php b/php/src/Google/Protobuf/Internal/Message.php index d304a12b474f3..2c41c7aa75f90 100644 --- a/php/src/Google/Protobuf/Internal/Message.php +++ b/php/src/Google/Protobuf/Internal/Message.php @@ -832,6 +832,9 @@ private function convertJsonValueToProtoValue( if (is_null($value)) { return $this->defaultValue($field); } + if (is_numeric($value)) { + return strval($value); + } if (!is_string($value)) { throw new GPBDecodeException( "String field only accepts string value"); diff --git a/php/tests/encode_decode_test.php b/php/tests/encode_decode_test.php index 57b1bf1f5fe36..1325db2cf8907 100644 --- a/php/tests/encode_decode_test.php +++ b/php/tests/encode_decode_test.php @@ -1148,4 +1148,14 @@ public function testJsonDecodeMapWithDefaultValueKey() $m->serializeToJsonString()); } + public function testJsonDecodeNumericStringMapKey() + { + $m = new TestMessage(); + $m->getMapStringString()["1"] = "1"; + $data = $m->serializeToJsonString(); + $this->assertSame("{\"mapStringString\":{\"1\":\"1\"}}", $data); + $n = new TestMessage(); + $n->mergeFromJsonString($data); + } + } diff --git a/tests.sh b/tests.sh index 2f453bdc8002a..618b6864fd2f1 100755 --- a/tests.sh +++ b/tests.sh @@ -482,7 +482,7 @@ build_php5.6_mac() { export PATH="$PHP_FOLDER/bin:$PATH" # Install phpunit - curl https://phar.phpunit.de/phpunit-5.6.10.phar -L -o phpunit.phar + curl https://phar.phpunit.de/phpunit-5.6.8.phar -L -o phpunit.phar chmod +x phpunit.phar sudo mv phpunit.phar /usr/local/bin/phpunit