mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-18 18:51:12 +01:00
Don't let users pick "whatever.git" as a repository short name, make "." work
Summary: Fixes T11902. - Periods now work in short names. - If you try to name something ".git", no dice. Test Plan: - Tried to name something "quack.git", was politely rejected. - Named something "quack.notgit", and it worked fine. - Cloned Mercurial and Git repositories over SSH with ".git" and non-".git" variants without hitting any issues. Reviewers: chad Reviewed By: chad Maniphest Tasks: T11902 Differential Revision: https://secure.phabricator.com/D16908
This commit is contained in:
parent
55e21565b5
commit
bf1cbc2499
5 changed files with 22 additions and 20 deletions
|
@ -101,7 +101,7 @@ final class PhabricatorDiffusionApplication extends PhabricatorApplication {
|
|||
')(?P<commit>[a-f0-9]+)'
|
||||
=> 'DiffusionCommitController',
|
||||
|
||||
'/source/(?P<repositoryShortName>[^/.]+)(?P<dotgit>\.git)?'
|
||||
'/source/(?P<repositoryShortName>[^/]+)'
|
||||
=> $repository_routes,
|
||||
|
||||
'/diffusion/' => array(
|
||||
|
|
|
@ -92,6 +92,8 @@ abstract class DiffusionController extends PhabricatorController {
|
|||
|
||||
$short_name = $request->getURIData('repositoryShortName');
|
||||
if (strlen($short_name)) {
|
||||
// If the short name ends in ".git", ignore it.
|
||||
$short_name = preg_replace('/\\.git\z/', '', $short_name);
|
||||
return $short_name;
|
||||
}
|
||||
|
||||
|
|
|
@ -88,13 +88,6 @@ final class DiffusionServeController extends DiffusionController {
|
|||
}
|
||||
}
|
||||
|
||||
// If the request was for a path like "/source/libphutil.git" but the
|
||||
// repository is not a Git repository, reject the request.
|
||||
$type_git = PhabricatorRepositoryType::REPOSITORY_TYPE_GIT;
|
||||
if ($request->getURIData('dotgit') && ($vcs !== $type_git)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $vcs;
|
||||
}
|
||||
|
||||
|
|
|
@ -442,6 +442,15 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
|
|||
'short names may not contain only numbers.',
|
||||
$slug));
|
||||
}
|
||||
|
||||
if (preg_match('/\\.git/', $slug)) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'The name "%s" is not a valid repository short name. Repository '.
|
||||
'short names must not end in ".git". This suffix will be added '.
|
||||
'automatically in appropriate contexts.',
|
||||
$slug));
|
||||
}
|
||||
}
|
||||
|
||||
public static function assertValidCallsign($callsign) {
|
||||
|
@ -592,21 +601,12 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
|
|||
}
|
||||
|
||||
public static function parseRepositoryServicePath($request_path, $vcs) {
|
||||
|
||||
// NOTE: In Mercurial over SSH, the path will begin without a leading "/",
|
||||
// so we're matching it optionally.
|
||||
|
||||
if ($vcs == PhabricatorRepositoryType::REPOSITORY_TYPE_GIT) {
|
||||
$maybe_git = '(?:\\.git)?';
|
||||
} else {
|
||||
$maybe_git = null;
|
||||
}
|
||||
$is_git = ($vcs == PhabricatorRepositoryType::REPOSITORY_TYPE_GIT);
|
||||
|
||||
$patterns = array(
|
||||
'(^'.
|
||||
'(?P<base>/?(?:diffusion|source)/(?P<identifier>[^/.]+))'.
|
||||
$maybe_git.
|
||||
'(?P<path>(?:/|.*)?)'.
|
||||
'(?P<base>/?(?:diffusion|source)/(?P<identifier>[^/]+))'.
|
||||
'(?P<path>.*)'.
|
||||
'\z)',
|
||||
);
|
||||
|
||||
|
@ -618,6 +618,10 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
|
|||
}
|
||||
|
||||
$identifier = $matches['identifier'];
|
||||
if ($is_git) {
|
||||
$identifier = preg_replace('/\\.git\z/', '', $identifier);
|
||||
}
|
||||
|
||||
$base = $matches['base'];
|
||||
$path = $matches['path'];
|
||||
break;
|
||||
|
|
|
@ -190,6 +190,9 @@ final class PhabricatorRepositoryTestCase
|
|||
'-ated',
|
||||
'_underscores_',
|
||||
'yes!',
|
||||
'quack.git',
|
||||
'git.git',
|
||||
'.git.git.git',
|
||||
|
||||
// 65-character names are no good.
|
||||
str_repeat('a', 65),
|
||||
|
|
Loading…
Reference in a new issue