Skip to content

Commit

Permalink
Fix issue with double ports
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin de Graaf committed Jan 19, 2021
1 parent b26700a commit 6fd854f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Parable Http

## 0.3.1
_Fixes_
- `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.

## 0.3.0

_Changes_
Expand Down
10 changes: 9 additions & 1 deletion src/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ public static function setPropertiesFromArray(self $uri, array $values): self
$uri->query = $values['query'] ?? null;
$uri->fragment = $values['fragment'] ?? null;

if ($uri->host !== null) {
$portPosition = strpos($uri->host, ':');

if ($portPosition !== false) {
$uri->host = substr_replace($uri->host, '', $portPosition);
}
}

if ($uri->path !== null) {
$uri->path = ltrim($uri->path, '/');
}
Expand All @@ -73,7 +81,7 @@ public function getUriString(): string
{
$restUri = $this->getUriRestString();

if (strlen($restUri) > 0 && !in_array(substr($restUri, 0, 1), ['?', '#'])) {
if (strlen($restUri) > 0 && !in_array($restUri[0], ['?', '#'])) {
$restUri = '/' . ltrim($restUri, '/');
}

Expand Down
8 changes: 8 additions & 0 deletions tests/UriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ public function testPortIsIgnoredWhenDefaultForSchemeHttps(): void
self::assertSame('https://devvoh.com', $uri->getUriString());
}

public function testDoublePortIsFixed(): void
{
$uri = new Uri('https://devvoh.com:8000:8000');

self::assertSame(8000, $uri->getPort());
self::assertSame('https://devvoh.com:8000', $uri->getUriString());
}

public function testGetPath(): void
{
self::assertSame('parable', $this->uri->getPath());
Expand Down

0 comments on commit 6fd854f

Please sign in to comment.