Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Message/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ final class Uri implements UriInterface
public function __construct($uri)
{
$parts = \parse_url($uri);
if ($parts === false || (isset($parts['scheme']) && !\preg_match('#^[a-z]+$#i', $parts['scheme'])) || (isset($parts['host']) && \preg_match('#[\s_%+]#', $parts['host']))) {
if ($parts === false || (isset($parts['scheme']) && !\preg_match('#^[a-z]+$#i', $parts['scheme'])) || (isset($parts['host']) && \preg_match('#[\s%+]#', $parts['host']))) {
throw new \InvalidArgumentException('Invalid URI given');
}

Expand Down Expand Up @@ -164,7 +164,7 @@ public function withHost($host)
return $this;
}

if (\preg_match('#[\s_%+]#', $host) || ($host !== '' && \parse_url('http://' . $host, \PHP_URL_HOST) !== $host)) {
if (\preg_match('#[\s%+]#', $host) || ($host !== '' && \parse_url('http://' . $host, \PHP_URL_HOST) !== $host)) {
throw new \InvalidArgumentException('Invalid URI host given');
}

Expand Down
13 changes: 13 additions & 0 deletions tests/Message/UriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ public static function provideValidUris()
yield [
'http://user%20name:pass%20word@localhost/path%20name?query%20name#frag%20ment'
];
yield [
'http://docker_container/'
];
}

/**
Expand Down Expand Up @@ -329,6 +332,16 @@ public function testWithHostReturnsNewInstanceWhenHostIsChanged()
$this->assertEquals('localhost', $uri->getHost());
}

public function testWithHostReturnsNewInstanceWhenHostIsChangedWithUnderscore()
{
$uri = new Uri('http://localhost');

$new = $uri->withHost('docker_container');
$this->assertNotSame($uri, $new);
$this->assertEquals('docker_container', $new->getHost());
$this->assertEquals('localhost', $uri->getHost());
}

public function testWithHostReturnsNewInstanceWithHostToLowerCaseWhenHostIsChangedWithUpperCase()
{
$uri = new Uri('http://localhost');
Expand Down