Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Prefix authority with double slash if present. #235

Closed
wants to merge 1 commit into from
Closed
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/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,11 +470,11 @@ private static function createUriString($scheme, $authority, $path, $query, $fra
$uri = '';

if (! empty($scheme)) {
$uri .= sprintf('%s://', $scheme);
$uri .= sprintf('%s:', $scheme);
}

if (! empty($authority)) {
$uri .= $authority;
$uri .= '//' . $authority;
}

if ($path) {
Expand Down
8 changes: 7 additions & 1 deletion test/UriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,12 @@ public function utf8QueryStringsDataProvider()
public function testUriDoesNotAppendColonToHostIfPortIsEmpty()
{
$uri = (new Uri())->withHost('google.com');
$this->assertEquals('google.com', (string) $uri);
$this->assertEquals('//google.com', (string) $uri);
}

public function testAuthorityIsPrefixedByDoubleSlashIfPresent()
{
$uri = (new Uri())->withHost('example.com');
$this->assertEquals('//example.com', (string) $uri);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is exactly the same as testUriDoesNotAppendColonToHostIfPortIsEmpty except the URL used... not sure we need both except for being explicit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was unsure too.

}
}