diff --git a/app/Rules/ValidGitRepositoryUrl.php b/app/Rules/ValidGitRepositoryUrl.php index 21509d65a..ba1aed11b 100644 --- a/app/Rules/ValidGitRepositoryUrl.php +++ b/app/Rules/ValidGitRepositoryUrl.php @@ -142,8 +142,8 @@ public function validate(string $attribute, mixed $value, Closure $fail): void return; } } elseif (str_starts_with($value, 'git://')) { - // Validate git:// protocol URL - if (! preg_match('/^git:\/\/[a-zA-Z0-9\.\-]+\/[a-zA-Z0-9\-_\/\.]+$/', $value)) { + // Validate git:// protocol URL (supports both git://host/path and git://host:port/path with tilde) + if (! preg_match('/^git:\/\/[a-zA-Z0-9\.\-]+(:[0-9]+)?[:\/][a-zA-Z0-9\-_\/\.~]+$/', $value)) { $fail('The :attribute is not a valid git:// URL.'); return; diff --git a/tests/Unit/ValidGitRepositoryUrlTest.php b/tests/Unit/ValidGitRepositoryUrlTest.php index 12eb419f2..da467dc4d 100644 --- a/tests/Unit/ValidGitRepositoryUrlTest.php +++ b/tests/Unit/ValidGitRepositoryUrlTest.php @@ -136,6 +136,7 @@ $validUrls = [ 'git://github.com/user/repo.git', 'git://gitlab.com/user/repo.git', + 'git://git.sr.ht:~user/repo.git', ]; foreach ($validUrls as $url) {