1
0
Fork 0

Fix package search not urlencoding the input (#10500)

pull/10514/head
Florian Engelhardt 2022-02-04 10:23:10 +01:00 committed by GitHub
parent e7c04e3e12
commit 3d82719b70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View File

@ -540,7 +540,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
$this->loadRootServerFile(600); $this->loadRootServerFile(600);
if ($this->searchUrl && $mode === self::SEARCH_FULLTEXT) { if ($this->searchUrl && $mode === self::SEARCH_FULLTEXT) {
$url = str_replace(array('%query%', '%type%'), array($query, $type), $this->searchUrl); $url = str_replace(array('%query%', '%type%'), array(urlencode($query), $type), $this->searchUrl);
$search = $this->httpDownloader->get($url, $this->options)->decodeJson(); $search = $this->httpDownloader->get($url, $this->options)->decodeJson();

View File

@ -202,6 +202,36 @@ class ComposerRepositoryTest extends TestCase
); );
} }
public function testSearchWithSpecialChars()
{
$repoConfig = array(
'url' => 'http://example.org',
);
$result = array(
'results' => array(
array(
'name' => 'foo',
'description' => null,
),
),
);
$httpDownloader = new HttpDownloaderMock(array(
'http://example.org/packages.json' => JsonFile::encode(array('search' => '/search.json?q=%query%&type=%type%')),
'http://example.org/search.json?q=foo+bar&type=' => JsonFile::encode(array()),
));
$eventDispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')
->disableOriginalConstructor()
->getMock();
$repository = new ComposerRepository($repoConfig, new NullIO, FactoryMock::createConfig(), $httpDownloader, $eventDispatcher);
$this->assertEmpty(
$repository->search('foo bar', RepositoryInterface::SEARCH_FULLTEXT)
);
}
public function testSearchWithAbandonedPackages() public function testSearchWithAbandonedPackages()
{ {
$repoConfig = array( $repoConfig = array(