Merge "API: Allow to pass whitespaces in MultiValue"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Mon, 29 Jan 2018 15:31:43 +0000 (15:31 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 29 Jan 2018 15:31:43 +0000 (15:31 +0000)
includes/api/ApiBase.php
tests/phpunit/includes/api/query/ApiQueryTest.php

index 1676f64..62d73f4 100644 (file)
@@ -1404,7 +1404,7 @@ abstract class ApiBase extends ContextSource {
        protected function parseMultiValue( $valueName, $value, $allowMultiple, $allowedValues,
                $allSpecifier = null, $limit1 = null, $limit2 = null
        ) {
-               if ( ( trim( $value ) === '' || trim( $value ) === "\x1f" ) && $allowMultiple ) {
+               if ( ( $value === '' || $value === "\x1f" ) && $allowMultiple ) {
                        return [];
                }
                $limit1 = $limit1 ?: self::LIMIT_SML1;
index 8026e54..88a2e62 100644 (file)
@@ -81,6 +81,19 @@ class ApiQueryTest extends ApiTestCase {
                $this->assertArrayHasKey( 'invalid', $data[0]['query']['pages'][-1] );
        }
 
+       public function testTitlesWithWhitespaces() {
+               $data = $this->doApiRequest( [
+                       'action' => 'query',
+                       'titles' => ' '
+               ] );
+
+               $this->assertArrayHasKey( 'query', $data[0] );
+               $this->assertArrayHasKey( 'pages', $data[0]['query'] );
+               $this->assertEquals( 1, count( $data[0]['query']['pages'] ) );
+               $this->assertArrayHasKey( -1, $data[0]['query']['pages'] );
+               $this->assertArrayHasKey( 'invalid', $data[0]['query']['pages'][-1] );
+       }
+
        /**
         * Test the ApiBase::titlePartToKey function
         *