Skip to content

Commit

Permalink
fix spaces from package search in URL
Browse files Browse the repository at this point in the history
  • Loading branch information
realFlowControl committed Jan 31, 2022
1 parent e8a1e25 commit 9b9ec0e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Composer/Repository/ComposerRepository.php
Expand Up @@ -540,7 +540,7 @@ public function search($query, $mode = 0, $type = null)
$this->loadRootServerFile(600);

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();

Expand Down
30 changes: 30 additions & 0 deletions tests/Composer/Test/Repository/ComposerRepositoryTest.php
Expand Up @@ -202,6 +202,36 @@ public function testSearchWithType()
);
}

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()
{
$repoConfig = array(
Expand Down

0 comments on commit 9b9ec0e

Please sign in to comment.