Skip to content

Commit 6fd854f

Browse files
author
Robin de Graaf
committed
Fix issue with double ports
1 parent b26700a commit 6fd854f

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Parable Http
22

3+
## 0.3.1
4+
_Fixes_
5+
- `Uri` could not deal with double ports, i.e. `devvoh.com:8000:8000` and would set `devvoh.com:8000` as the host, causing issues. This is now fixed. The host is no longer allowed to have port numbers in it.
6+
37
## 0.3.0
48

59
_Changes_

src/Uri.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ public static function setPropertiesFromArray(self $uri, array $values): self
6262
$uri->query = $values['query'] ?? null;
6363
$uri->fragment = $values['fragment'] ?? null;
6464

65+
if ($uri->host !== null) {
66+
$portPosition = strpos($uri->host, ':');
67+
68+
if ($portPosition !== false) {
69+
$uri->host = substr_replace($uri->host, '', $portPosition);
70+
}
71+
}
72+
6573
if ($uri->path !== null) {
6674
$uri->path = ltrim($uri->path, '/');
6775
}
@@ -73,7 +81,7 @@ public function getUriString(): string
7381
{
7482
$restUri = $this->getUriRestString();
7583

76-
if (strlen($restUri) > 0 && !in_array(substr($restUri, 0, 1), ['?', '#'])) {
84+
if (strlen($restUri) > 0 && !in_array($restUri[0], ['?', '#'])) {
7785
$restUri = '/' . ltrim($restUri, '/');
7886
}
7987

tests/UriTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ public function testPortIsIgnoredWhenDefaultForSchemeHttps(): void
8080
self::assertSame('https://devvoh.com', $uri->getUriString());
8181
}
8282

83+
public function testDoublePortIsFixed(): void
84+
{
85+
$uri = new Uri('https://devvoh.com:8000:8000');
86+
87+
self::assertSame(8000, $uri->getPort());
88+
self::assertSame('https://devvoh.com:8000', $uri->getUriString());
89+
}
90+
8391
public function testGetPath(): void
8492
{
8593
self::assertSame('parable', $this->uri->getPath());

0 commit comments

Comments
 (0)