Page MenuHomePhabricator

D9823.id23578.diff
No OneTemporary

D9823.id23578.diff

diff --git a/src/parser/PhutilURI.php b/src/parser/PhutilURI.php
--- a/src/parser/PhutilURI.php
+++ b/src/parser/PhutilURI.php
@@ -141,6 +141,22 @@
return $this;
}
+ public function appendPath($path) {
+ $first = strlen($path) ? $path[0] : null;
+ $last = strlen($this->path) ? $this->path[strlen($this->path) - 1] : null;
+
+ if (!$this->path) {
+ return $this->setPath($path);
+ } else if ($first === '/' && $last === '/') {
+ $path = substr($path, 1);
+ } else if ($first !== '/' && $last !== '/') {
+ $path = '/'.$path;
+ }
+
+ $this->path .= $path;
+ return $this;
+ }
+
public function getPath() {
return $this->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
@@ -81,4 +81,24 @@
$this->assertEqual('', $uri->getDomain());
}
+ public function testAppendPath() {
+ $uri = new PhutilURI('http://example.com');
+ $uri->appendPath('foo');
+ $this->assertEqual('http://example.com/foo', $uri->__toString());
+ $uri->appendPath('bar');
+ $this->assertEqual('http://example.com/foo/bar', $uri->__toString());
+
+ $uri = new PhutilURI('http://example.com');
+ $uri->appendPath('/foo/');
+ $this->assertEqual('http://example.com/foo/', $uri->__toString());
+ $uri->appendPath('/bar/');
+ $this->assertEqual('http://example.com/foo/bar/', $uri->__toString());
+
+ $uri = new PhutilURI('http://example.com');
+ $uri->appendPath('foo');
+ $this->assertEqual('http://example.com/foo', $uri->__toString());
+ $uri->appendPath('/bar/');
+ $this->assertEqual('http://example.com/foo/bar/', $uri->__toString());
+ }
+
}

File Metadata

Mime Type
text/plain
Expires
Wed, Mar 12, 3:42 PM (2 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7589178
Default Alt Text
D9823.id23578.diff (1 KB)

Event Timeline