@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+22 -20
+1 -1
src/applications/diffusion/application/PhabricatorDiffusionApplication.php
··· 101 101 ')(?P<commit>[a-f0-9]+)' 102 102 => 'DiffusionCommitController', 103 103 104 - '/source/(?P<repositoryShortName>[^/.]+)(?P<dotgit>\.git)?' 104 + '/source/(?P<repositoryShortName>[^/]+)' 105 105 => $repository_routes, 106 106 107 107 '/diffusion/' => array(
+2
src/applications/diffusion/controller/DiffusionController.php
··· 92 92 93 93 $short_name = $request->getURIData('repositoryShortName'); 94 94 if (strlen($short_name)) { 95 + // If the short name ends in ".git", ignore it. 96 + $short_name = preg_replace('/\\.git\z/', '', $short_name); 95 97 return $short_name; 96 98 } 97 99
-7
src/applications/diffusion/controller/DiffusionServeController.php
··· 88 88 } 89 89 } 90 90 91 - // If the request was for a path like "/source/libphutil.git" but the 92 - // repository is not a Git repository, reject the request. 93 - $type_git = PhabricatorRepositoryType::REPOSITORY_TYPE_GIT; 94 - if ($request->getURIData('dotgit') && ($vcs !== $type_git)) { 95 - return null; 96 - } 97 - 98 91 return $vcs; 99 92 } 100 93
+16 -12
src/applications/repository/storage/PhabricatorRepository.php
··· 442 442 'short names may not contain only numbers.', 443 443 $slug)); 444 444 } 445 + 446 + if (preg_match('/\\.git/', $slug)) { 447 + throw new Exception( 448 + pht( 449 + 'The name "%s" is not a valid repository short name. Repository '. 450 + 'short names must not end in ".git". This suffix will be added '. 451 + 'automatically in appropriate contexts.', 452 + $slug)); 453 + } 445 454 } 446 455 447 456 public static function assertValidCallsign($callsign) { ··· 592 601 } 593 602 594 603 public static function parseRepositoryServicePath($request_path, $vcs) { 595 - 596 - // NOTE: In Mercurial over SSH, the path will begin without a leading "/", 597 - // so we're matching it optionally. 598 - 599 - if ($vcs == PhabricatorRepositoryType::REPOSITORY_TYPE_GIT) { 600 - $maybe_git = '(?:\\.git)?'; 601 - } else { 602 - $maybe_git = null; 603 - } 604 + $is_git = ($vcs == PhabricatorRepositoryType::REPOSITORY_TYPE_GIT); 604 605 605 606 $patterns = array( 606 607 '(^'. 607 - '(?P<base>/?(?:diffusion|source)/(?P<identifier>[^/.]+))'. 608 - $maybe_git. 609 - '(?P<path>(?:/|.*)?)'. 608 + '(?P<base>/?(?:diffusion|source)/(?P<identifier>[^/]+))'. 609 + '(?P<path>.*)'. 610 610 '\z)', 611 611 ); 612 612 ··· 618 618 } 619 619 620 620 $identifier = $matches['identifier']; 621 + if ($is_git) { 622 + $identifier = preg_replace('/\\.git\z/', '', $identifier); 623 + } 624 + 621 625 $base = $matches['base']; 622 626 $path = $matches['path']; 623 627 break;
+3
src/applications/repository/storage/__tests__/PhabricatorRepositoryTestCase.php
··· 190 190 '-ated', 191 191 '_underscores_', 192 192 'yes!', 193 + 'quack.git', 194 + 'git.git', 195 + '.git.git.git', 193 196 194 197 // 65-character names are no good. 195 198 str_repeat('a', 65),