Browse Source

Allow URLs without slash in the path part, fixes #917

Jordi Boggiano 7 years ago
parent
commit
3735498237

+ 1 - 1
src/Packagist/WebBundle/Controller/ApiController.php

@@ -117,7 +117,7 @@ class ApiController extends Controller
             $urlRegex = '{^(?:ssh://git@|https?://|git://|git@)?(?P<host>[a-z0-9.-]+)(?::[0-9]+/|[:/])(?P<path>[\w.-]+(?:/[\w.-]+?)+)(?:\.git|/)?$}i';
             $url = $payload['project']['git_http_url'];
         } elseif (isset($payload['repository']['url'])) { // github/anything hook
-            $urlRegex = '{^(?:ssh://git@|https?://|git://|git@)?(?P<host>[a-z0-9.-]+)(?::[0-9]+/|[:/])(?P<path>[\w.-]+(?:/[\w.-]+?)+)(?:\.git|/)?$}i';
+            $urlRegex = '{^(?:ssh://git@|https?://|git://|git@)?(?P<host>[a-z0-9.-]+)(?::[0-9]+/|[:/])(?P<path>[\w.-]+(?:/[\w.-]+?)*)(?:\.git|/)?$}i';
             $url = $payload['repository']['url'];
             $url = str_replace('https://api.github.com/repos', 'https://github.com', $url);
         } elseif (isset($payload['repository']['links']['html']['href'])) { // bitbucket push event payload

+ 3 - 3
src/Packagist/WebBundle/Tests/Controller/ApiControllerTest.php

@@ -107,6 +107,7 @@ class ApiControllerTest extends WebTestCase
             array('github', 'git@github.com:user/repo.git', true),
             array('github', 'git@github.com:user/repo', true),
             array('github', 'https://github.com/user/repo/', true),
+            array('github', 'https://github.com/user/', true), // not strictly valid but marked as valid due to support for https://example.org/some-repo.git
 
             // valid bitbucket URLs
             array('bitbucket', 'bitbucket.org/user/repo', true),
@@ -115,20 +116,19 @@ class ApiControllerTest extends WebTestCase
 
             // valid others
             array('update-package', 'https://ghe.example.org/user/repository', true),
+            array('update-package', 'https://example.org/some-repo.git', true),
             array('update-package', 'https://gitlab.org/user/repository', true),
             array('update-package', 'https://gitlab.org/user/sub/group/lala/repository', true),
             array('update-package', 'ssh://git@stash.xxxxx.com/uuuuu/qqqqq.git', true),
             array('update-package', 'ssh://git@stash.xxxxx.com:2222/uuuuu/qqqqq.git', true),
+            array('update-package', 'ssh://git@stash.zzzzz.com/kkkkk.git', true),
 
             // invalid URLs
             array('github', 'php://github.com/user/repository', false),
             array('github', 'javascript://github.com/user/repository', false),
             array('github', 'http://', false),
-            array('github', 'https://github.com/user/', false),
-            array('github', 'https://github.com/user', false),
             array('github', 'https://github.com/', false),
             array('github', 'https://github.com', false),
-            array('update-package', 'ssh://git@stash.zzzzz.com/kkkkk.git', false),
             array('update-package', 'ssh://ghe.example.org/user/jjjjj.git', false),
         );
     }