Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15420998
D11338.id27242.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D11338.id27242.diff
View Options
diff --git a/src/parser/PhutilURI.php b/src/parser/PhutilURI.php
--- a/src/parser/PhutilURI.php
+++ b/src/parser/PhutilURI.php
@@ -144,7 +144,15 @@
return $this;
}
public function getPort() {
- return $this->port;
+ static $default_ports = array(
+ 'http' => '80',
+ 'https' => '443',
+ 'ssh' => '22',
+ );
+
+ return nonempty(
+ $this->port,
+ idx($default_ports, $this->getProtocol()));
}
public function setPath($path) {
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
@@ -32,7 +32,6 @@
$this->assertEqual('git', $uri->getUser(), 'user');
$this->assertEqual('', $uri->getPass(), 'pass');
$this->assertEqual('example.com', $uri->getDomain(), 'domain');
- $this->assertEqual('', $uri->getPort(), 'port');
$this->assertEqual('/example/example.git', $uri->getPath(), 'path');
$this->assertEqual(array(), $uri->getQueryParams(), 'query params');
@@ -116,4 +115,15 @@
$uri->getQueryParams());
}
+ public function testDefaultPorts() {
+ $uri = new PhutilURI('http://www.example.com');
+ $this->assertEqual('80', $uri->getPort());
+
+ $uri = new PhutilURI('https://www.example.com');
+ $this->assertEqual('443', $uri->getPort());
+
+ $uri = new PhutilURI('ssh://git@example.com/example/example.git');
+ $this->assertEqual('22', $uri->getPort());
+ }
+
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Mar 22, 8:00 PM (5 d, 10 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7717349
Default Alt Text
D11338.id27242.diff (1 KB)
Attached To
Mode
D11338: Add default ports to `PhutilURI`
Attached
Detach File
Event Timeline
Log In to Comment