fix: return null for invalid repository URLs

This commit is contained in:
Andras Bacsai 2026-09-04 15:44:18 +02:00
parent 053b030c42
commit 2ebbc5113e
2 changed files with 16 additions and 1 deletions

View file

@ -714,7 +714,7 @@ public function gitCommits(): Attribute
);
}
public function gitCommitLink($link): string
public function gitCommitLink($link): ?string
{
if (! is_null(data_get($this, 'source.html_url')) && ! is_null(data_get($this, 'git_repository')) && ! is_null(data_get($this, 'git_branch'))) {
if (str($this->source->html_url)->contains('bitbucket')) {
@ -731,6 +731,10 @@ public function gitCommitLink($link): string
$git_repository = 'https://'.parse_url($git_repository, PHP_URL_HOST).parse_url($git_repository, PHP_URL_PATH);
}
if (! filter_var($git_repository, FILTER_VALIDATE_URL)) {
return null;
}
$url = Url::fromString(Str::replaceEnd('.git', '', $git_repository));
$url = $url->withUserInfo('');
$commitPath = str($git_repository)->contains('bitbucket') ? 'commits' : 'commit';

View file

@ -26,3 +26,14 @@
'https://bitbucket.org/coollabsio/coolify/commits/1234567890abcdef',
],
]);
it('does not generate commit links from incomplete repository URLs', function (string $repository) {
$application = new Application;
$application->setRelation('source', null);
$application->git_repository = $repository;
expect($application->gitCommitLink('1234567890abcdef'))->toBeNull();
})->with([
'missing host' => 'https://',
'missing scheme' => 'github.com/coollabsio/coolify',
]);