Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15416353
D10515.id25261.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D10515.id25261.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
@@ -15,7 +15,20 @@
private $fragment;
public function __construct($uri) {
- $parts = parse_url($uri);
+ $uri = (string)$uri;
+
+ $matches = null;
+ if (preg_match('(^([^/]*://[^/]*)([?].*)\z)', $uri, $matches)) {
+ // If the URI is something like `idea://open?file=/path/to/file`, the
+ // `parse_url()` function will parse `open?file=` as the host. This is
+ // not the expected result. Break the URI into two pieces, stick a slash
+ // in between them, parse that, then remove the path. See T6106.
+
+ $parts = parse_url($matches[1].'/'.$matches[2]);
+ unset($parts['path']);
+ } else {
+ $parts = parse_url($uri);
+ }
// The parse_url() call will accept URIs with leading whitespace, but many
// other tools (like git) will not. See T4913 for a specific example. If
@@ -26,6 +39,7 @@
}
}
+
// NOTE: `parse_url()` is very liberal about host names; fail the parse if
// the host looks like garbage.
if ($parts) {
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
@@ -99,4 +99,21 @@
$this->assertEqual('http://example.com/foo/bar/', $uri->__toString());
}
+ public function testUnusualURIs() {
+ $uri = new PhutilURI('file:///path/to/file');
+ $this->assertEqual('file', $uri->getProtocol(), 'protocol');
+ $this->assertEqual('', $uri->getDomain(), 'domain');
+ $this->assertEqual('/path/to/file', $uri->getPath(), 'path');
+
+ $uri = new PhutilURI('idea://open?x=/');
+ $this->assertEqual('idea', $uri->getProtocol(), 'protocol');
+ $this->assertEqual('open', $uri->getDomain(), 'domain');
+ $this->assertEqual('', $uri->getPath(), 'path');
+ $this->assertEqual(
+ array(
+ 'x' => '/',
+ ),
+ $uri->getQueryParams());
+ }
+
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Mar 21, 10:36 AM (3 w, 5 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7706670
Default Alt Text
D10515.id25261.diff (2 KB)
Attached To
Mode
D10515: Parse unusual editor URIs with no domain in the way users expect
Attached
Detach File
Event Timeline
Log In to Comment