1
0
Fork 0

GitHubDriver: better handle empty composer.json file (#11552)

pull/11536/head
Stephan 2023-07-21 10:09:32 +01:00 committed by GitHub
parent 8f49166ec6
commit cf8ea3c70e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions

View File

@ -310,7 +310,7 @@ class GitHubDriver extends VcsDriver
$resource = $this->getContents($resource['git_url'])->decodeJson(); $resource = $this->getContents($resource['git_url'])->decodeJson();
} }
if (empty($resource['content']) || $resource['encoding'] !== 'base64' || !($content = base64_decode($resource['content']))) { if (!isset($resource['content']) || $resource['encoding'] !== 'base64' || false === ($content = base64_decode($resource['content']))) {
throw new \RuntimeException('Could not retrieve ' . $file . ' for '.$identifier); throw new \RuntimeException('Could not retrieve ' . $file . ' for '.$identifier);
} }

View File

@ -401,6 +401,34 @@ class GitHubDriverTest extends TestCase
]; ];
} }
public function testGetEmptyFileContent(): void
{
$repoUrl = 'http://github.com/composer/packagist';
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
$io->expects($this->any())
->method('isInteractive')
->will($this->returnValue(true));
$httpDownloader = $this->getHttpDownloaderMock($io, $this->config);
$httpDownloader->expects(
[
['url' => 'https://api.github.com/repos/composer/packagist', 'body' => '{"master_branch": "test_master", "owner": {"login": "composer"}, "name": "packagist", "archived": true}'],
['url' => 'https://api.github.com/repos/composer/packagist/contents/composer.json?ref=main', 'body' => '{"encoding":"base64","content":""}'],
],
true
);
$repoConfig = [
'url' => $repoUrl,
];
$gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, $httpDownloader, $this->getProcessExecutorMock());
$gitHubDriver->initialize();
$this->assertSame('', $gitHubDriver->getFileContent('composer.json', 'main'));
}
/** /**
* @param string|object $object * @param string|object $object
* @param mixed $value * @param mixed $value