Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F56082742
D2285.id5756.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
D2285.id5756.diff
View Options
diff --git a/src/HTTP/URL.php b/src/HTTP/URL.php
--- a/src/HTTP/URL.php
+++ b/src/HTTP/URL.php
@@ -73,20 +73,37 @@
return "";
}
+ private function getUrlParts() : array {
+ preg_match("@://(.*)@", $this->url, $matches);
+ return explode("/", $matches[1], 2);
+ }
+
public function getDomain () : string {
- if (preg_match("@://(.*?)/@", $this->url, $matches)) {
- return self::beautifyDomain($matches[1]);
+ if (strpos($this->url, "://") === false) {
+ return "";
}
- return "";
+ $domain = $this->getUrlParts()[0];
+
+ if ($domain === "") {
+ return "";
+ }
+
+ return self::beautifyDomain($domain);
}
public function getQuery () : string {
- if (preg_match("@(://.*?)?(/.*)@", $this->url, $matches)) {
- return $this->beautifyQuery($matches[2]);
+ if (strpos($this->url, "://") === false) {
+ return $this->url;
}
- return "";
+ $parts = $this->getUrlParts();
+
+ if (count($parts) < 2 || $parts[1] === "" || $parts[1] === "/") {
+ return "/";
+ }
+
+ return "/" . $this->beautifyQuery($parts[1]);
}
public function setProtocol ($protocol) : self {
diff --git a/tests/HTTP/URLTest.php b/tests/HTTP/URLTest.php
--- a/tests/HTTP/URLTest.php
+++ b/tests/HTTP/URLTest.php
@@ -56,29 +56,28 @@
$this->assertEquals("/xizzy", $url->getQuery());
}
- public function testSetQueryWithSlashForgotten () : void {
- $url = new URL("https://acme.tld/foo");
- $url->setQuery("xizzy");
-
- $this->assertEquals("/xizzy", $url->getQuery());
- }
-
/**
* @dataProvider provideURLsAndComponents
*/
- public function testCompose ($expectedUrl, $domain, $protocol, $query) {
+ public function testCompose ($url, $domain, $protocol, $query,
+ $expectedUrl = null) {
$this->assertEquals(
- $expectedUrl,
+ $expectedUrl ?? $url,
URL::compose($protocol, $domain, $query)->__toString()
);
}
public function provideURLsAndComponents () : iterable {
+ // base URL, domain, protocol, query[, expected URL]
+ // When omitted, the expected URL is the base URL.
+
yield ["http://foo/bar", "foo", "http", "/bar"];
yield ["https://xn--dghrefn-mxa.nasqueron.org/", "dæghrefn.nasqueron.org", "https", "/"];
yield ["://foo/bar", "foo", "", "/bar"];
yield ["/bar", "", "", "/bar"];
yield ["http://foo/bar%20quux", "foo", "http", "/bar quux"];
+ yield ["https://foo/", "foo", "https", "/"];
+ yield ["https://foo", "foo", "https", "/", "https://foo/"];
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Nov 3, 16:52 (1 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4247159
Default Alt Text
D2285.id5756.diff (2 KB)
Attached To
Mode
D2285: Parse correctly https://domain.tld without query or final /
Attached
Detach File
Event Timeline
Log In to Comment