Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F23014863
D8900.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D8900.diff
View Options
Index: src/parser/PhutilGitURI.php
===================================================================
--- src/parser/PhutilGitURI.php
+++ src/parser/PhutilGitURI.php
@@ -30,6 +30,12 @@
}
private static function parseURI($uri) {
+ // See T4913. Fail the parse if there is leading whitespace; stricter
+ // systems will not accept these URIs.
+ if (ltrim($uri) !== $uri) {
+ return null;
+ }
+
$user = '(?:([^@]+)@)?';
$domain = '([^:]+)';
$path = ':(.*)';
Index: src/parser/PhutilURI.php
===================================================================
--- src/parser/PhutilURI.php
+++ src/parser/PhutilURI.php
@@ -17,6 +17,15 @@
public function __construct($uri) {
$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
+ // the input string has leading whitespace, fail the parse.
+ if ($parts) {
+ if (ltrim($uri) != $uri) {
+ $parts = false;
+ }
+ }
+
// NOTE: `parse_url()` is very liberal about host names; fail the parse if
// the host looks like garbage.
if ($parts) {
Index: src/parser/__tests__/PhutilGitURITestCase.php
===================================================================
--- src/parser/__tests__/PhutilGitURITestCase.php
+++ src/parser/__tests__/PhutilGitURITestCase.php
@@ -19,5 +19,10 @@
$this->assertEqual('host.com:path/to/something', (string)$uri);
}
+ public function testStrictGitURIParsingOfLeadingWhitespace() {
+ $uri = new PhutilURI(' user@example.com');
+ $this->assertEqual('', $uri->getDomain());
+ }
+
}
Index: src/parser/__tests__/PhutilURITestCase.php
===================================================================
--- src/parser/__tests__/PhutilURITestCase.php
+++ src/parser/__tests__/PhutilURITestCase.php
@@ -76,4 +76,9 @@
$this->assertEqual('', $uri->getDomain());
}
+ public function testStrictURIParsingOfLeadingWhitespace() {
+ $uri = new PhutilURI(' http://example.com/');
+ $this->assertEqual('', $uri->getDomain());
+ }
+
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 27, 6:33 AM (13 h, 28 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
17420077
Default Alt Text
D8900.diff (2 KB)
Attached To
Mode
D8900: xzcb
Attached
Detach File
Event Timeline
Log In to Comment