From: Yuri Astrakhan Date: Fri, 11 Dec 2015 22:45:14 +0000 (+0300) Subject: Fixed incorrect size for api result X-Git-Tag: 1.31.0-rc.0~8722 X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=commitdiff_plain;h=393378d2cb5725104153b0f0faf5840a2bdd2040;p=lhc%2Fweb%2Fwiklou.git Fixed incorrect size for api result Added a unit test to highlight the problem Change-Id: I5d4bcb755bd3686a92e7b111946a49892699729f --- diff --git a/includes/api/ApiResult.php b/includes/api/ApiResult.php index e28cb82703..bd5fe08cea 100644 --- a/includes/api/ApiResult.php +++ b/includes/api/ApiResult.php @@ -1090,7 +1090,7 @@ class ApiResult implements ApiSerializable { $s = 0; if ( is_array( $value ) ) { foreach ( $value as $k => $v ) { - if ( !self::isMetadataKey( $s ) ) { + if ( !self::isMetadataKey( $k ) ) { $s += self::valueSize( $v ); } } diff --git a/tests/phpunit/includes/api/ApiResultTest.php b/tests/phpunit/includes/api/ApiResultTest.php index d43db71421..9dbde3d93f 100644 --- a/tests/phpunit/includes/api/ApiResultTest.php +++ b/tests/phpunit/includes/api/ApiResultTest.php @@ -458,6 +458,13 @@ class ApiResultTest extends MediaWikiTestCase { ); } + // Add two values and some metadata, but ensure metadata is not counted + $result = new ApiResult( 100 ); + $obj = array( 'attr' => '12345' ); + ApiResult::setContentValue( $obj, 'content', '1234567890' ); + $this->assertTrue( $result->addValue( null, 'foo', $obj ) ); + $this->assertSame( 15, $result->getSize() ); + $result = new ApiResult( 10 ); $formatter = new ApiErrorFormatter( $result, Language::factory( 'en' ), 'none', false ); $result->setErrorFormatter( $formatter );