mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-31 08:58:20 +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]+)'
|
')(?P<commit>[a-f0-9]+)'
|
||||||
=> 'DiffusionCommitController',
|
=> 'DiffusionCommitController',
|
||||||
|
|
||||||
'/source/(?P<repositoryShortName>[^/.]+)(?P<dotgit>\.git)?'
|
'/source/(?P<repositoryShortName>[^/]+)'
|
||||||
=> $repository_routes,
|
=> $repository_routes,
|
||||||
|
|
||||||
'/diffusion/' => array(
|
'/diffusion/' => array(
|
||||||
|
|
|
@ -92,6 +92,8 @@ abstract class DiffusionController extends PhabricatorController {
|
||||||
|
|
||||||
$short_name = $request->getURIData('repositoryShortName');
|
$short_name = $request->getURIData('repositoryShortName');
|
||||||
if (strlen($short_name)) {
|
if (strlen($short_name)) {
|
||||||
|
// If the short name ends in ".git", ignore it.
|
||||||
|
$short_name = preg_replace('/\\.git\z/', '', $short_name);
|
||||||
return $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;
|
return $vcs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -442,6 +442,15 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
|
||||||
'short names may not contain only numbers.',
|
'short names may not contain only numbers.',
|
||||||
$slug));
|
$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) {
|
public static function assertValidCallsign($callsign) {
|
||||||
|
@ -592,21 +601,12 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function parseRepositoryServicePath($request_path, $vcs) {
|
public static function parseRepositoryServicePath($request_path, $vcs) {
|
||||||
|
$is_git = ($vcs == PhabricatorRepositoryType::REPOSITORY_TYPE_GIT);
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
$patterns = array(
|
$patterns = array(
|
||||||
'(^'.
|
'(^'.
|
||||||
'(?P<base>/?(?:diffusion|source)/(?P<identifier>[^/.]+))'.
|
'(?P<base>/?(?:diffusion|source)/(?P<identifier>[^/]+))'.
|
||||||
$maybe_git.
|
'(?P<path>.*)'.
|
||||||
'(?P<path>(?:/|.*)?)'.
|
|
||||||
'\z)',
|
'\z)',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -618,6 +618,10 @@ final class PhabricatorRepository extends PhabricatorRepositoryDAO
|
||||||
}
|
}
|
||||||
|
|
||||||
$identifier = $matches['identifier'];
|
$identifier = $matches['identifier'];
|
||||||
|
if ($is_git) {
|
||||||
|
$identifier = preg_replace('/\\.git\z/', '', $identifier);
|
||||||
|
}
|
||||||
|
|
||||||
$base = $matches['base'];
|
$base = $matches['base'];
|
||||||
$path = $matches['path'];
|
$path = $matches['path'];
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -190,6 +190,9 @@ final class PhabricatorRepositoryTestCase
|
||||||
'-ated',
|
'-ated',
|
||||||
'_underscores_',
|
'_underscores_',
|
||||||
'yes!',
|
'yes!',
|
||||||
|
'quack.git',
|
||||||
|
'git.git',
|
||||||
|
'.git.git.git',
|
||||||
|
|
||||||
// 65-character names are no good.
|
// 65-character names are no good.
|
||||||
str_repeat('a', 65),
|
str_repeat('a', 65),
|
||||||
|
|
Loading…
Add table
Reference in a new issue