Merge pull request #5644 from TeBoring/fix-4765

Convert integer to string if field is string field in json
pull/5653/head v3.7.0rc1
Paul Yang 6 years ago committed by GitHub
commit 74f667ddc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      conformance/failure_list_php.txt
  2. 3
      php/src/Google/Protobuf/Internal/Message.php
  3. 10
      php/tests/encode_decode_test.php
  4. 2
      tests.sh

@ -13,6 +13,8 @@ Required.Proto3.JsonInput.FloatFieldTooSmall
Required.Proto3.JsonInput.DoubleFieldTooSmall Required.Proto3.JsonInput.DoubleFieldTooSmall
Required.Proto3.JsonInput.Int32FieldNotInteger Required.Proto3.JsonInput.Int32FieldNotInteger
Required.Proto3.JsonInput.Int64FieldNotInteger Required.Proto3.JsonInput.Int64FieldNotInteger
Required.Proto3.JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotInt
Required.Proto3.JsonInput.StringFieldNotAString
Required.Proto3.JsonInput.Uint32FieldNotInteger Required.Proto3.JsonInput.Uint32FieldNotInteger
Required.Proto3.JsonInput.Uint64FieldNotInteger Required.Proto3.JsonInput.Uint64FieldNotInteger
Required.Proto3.JsonInput.Int32FieldLeadingSpace Required.Proto3.JsonInput.Int32FieldLeadingSpace

@ -832,6 +832,9 @@ class Message
if (is_null($value)) { if (is_null($value)) {
return $this->defaultValue($field); return $this->defaultValue($field);
} }
if (is_numeric($value)) {
return strval($value);
}
if (!is_string($value)) { if (!is_string($value)) {
throw new GPBDecodeException( throw new GPBDecodeException(
"String field only accepts string value"); "String field only accepts string value");

@ -1148,4 +1148,14 @@ class EncodeDecodeTest extends TestBase
$m->serializeToJsonString()); $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);
}
} }

@ -482,7 +482,7 @@ build_php5.6_mac() {
export PATH="$PHP_FOLDER/bin:$PATH" export PATH="$PHP_FOLDER/bin:$PATH"
# Install phpunit # 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 chmod +x phpunit.phar
sudo mv phpunit.phar /usr/local/bin/phpunit sudo mv phpunit.phar /usr/local/bin/phpunit

Loading…
Cancel
Save