mirror of
https://github.com/coollabsio/coolify.git
synced 2026-09-25 07:50:35 -05:00
fix: return null for invalid repository URLs
This commit is contained in:
@@ -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',
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user