Browse Source

Detect invalid ssh URLs, fixes #1124

Jordi Boggiano 12 years ago
parent
commit
04c6670f0c

+ 4 - 0
src/Composer/Downloader/GitDownloader.php

@@ -265,6 +265,10 @@ class GitDownloader extends VcsDownloader
     {
         $handler = array($this, 'outputHandler');
 
+        if (preg_match('{^ssh://[^@]+@[^:]+:[^0-9]+}', $url)) {
+            throw new \InvalidArgumentException('The source URL '.$url.' is invalid, ssh URLs should have a port number after ":".'."\n".'Use ssh://git@example.com:22/path or just git@example.com:path if you do not want to provide a password or custom port.');
+        }
+
         // public github, autoswitch protocols
         if (preg_match('{^(?:https?|git)(://github.com/.*)}', $url, $match)) {
             $protocols = $this->config->get('github-protocols');

+ 4 - 0
src/Composer/Repository/Vcs/GitDriver.php

@@ -45,6 +45,10 @@ class GitDriver extends VcsDriver
                 throw new \RuntimeException('Can not clone '.$this->url.' to access package information. The "'.dirname($this->repoDir).'" directory is not writable by the current user.');
             }
 
+            if (preg_match('{^ssh://[^@]+@[^:]+:[^0-9]+}', $this->url)) {
+                throw new \InvalidArgumentException('The source URL '.$this->url.' is invalid, ssh URLs should have a port number after ":".'."\n".'Use ssh://git@example.com:22/path or just git@example.com:path if you do not want to provide a password or custom port.');
+            }
+
             // update the repo if it is a valid git repository
             if (is_dir($this->repoDir) && 0 === $this->process->execute('git remote', $output, $this->repoDir)) {
                 if (0 !== $this->process->execute('git remote update --prune origin', $output, $this->repoDir)) {