diff --git a/src/parser/PhutilURI.php b/src/parser/PhutilURI.php --- a/src/parser/PhutilURI.php +++ b/src/parser/PhutilURI.php @@ -350,6 +350,13 @@ return false; } + // If the second part only contains digits, assume we're looking at + // casually specified "domain.com:123" URI, not a Git URI pointed at an + // entirely numeric relative path. + if (preg_match('(^\d+\z)', $last)) { + return false; + } + // If the first part has a "." or an "@" in it, interpret it as a domain // or a "user@host" string. if (preg_match('([.@])', $head)) { diff --git a/src/parser/__tests__/PhutilURITestCase.php b/src/parser/__tests__/PhutilURITestCase.php --- a/src/parser/__tests__/PhutilURITestCase.php +++ b/src/parser/__tests__/PhutilURITestCase.php @@ -177,6 +177,14 @@ $uri = new PhutilURI('user@localhost:todo.txt'); $this->assertEqual('localhost', $uri->getDomain()); + + // This could either be a Git URI with relative path "22", or a normal URI + // with port "22". We should assume it is a port number because this is + // relatively common, while relative Git URIs pointing at numeric filenames + // are bizarre. + $uri = new PhutilURI('domain.com:22'); + $this->assertEqual('domain.com', $uri->getDomain()); + $this->assertEqual('22', $uri->getPort()); } public function testDefaultPorts() {