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
+5 -1
View File
@@ -714,7 +714,7 @@ class Application extends BaseModel
);
}
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 @@ class Application extends BaseModel
$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';
@@ -26,3 +26,14 @@ it('generates commit links for direct repository remotes', function (string $rep
'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',
]);