Skip to content

Commit

Permalink
Merge branch 'bugfix/uri-ToString-method'
Browse files Browse the repository at this point in the history
Closes #52
  • Loading branch information
akrabat committed Sep 8, 2018
2 parents 5139884 + 1589b3b commit 5924b12
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
8 changes: 8 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,13 @@
"psr-4": {
"Slim\\Tests\\Http\\": "tests/"
}
},
"scripts": {
"test": [
"@phpunit",
"@phpcs"
],
"phpunit": "php vendor/bin/phpunit",
"phpcs": "php vendor/bin/phpcs"
}
}
8 changes: 4 additions & 4 deletions src/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -768,8 +768,8 @@ public function __toString()

$path = '/' . ltrim($path, '/');

return ($scheme ? $scheme . ':' : '')
. ($authority ? '//' . $authority : '')
return ($scheme !== '' ? $scheme . ':' : '')
. ($authority !== '' ? '//' . $authority : '')
. $path
. ($query !== '' ? '?' . $query : '')
. ($fragment !== '' ? '#' . $fragment : '');
Expand All @@ -789,7 +789,7 @@ public function getBaseUrl()
$scheme = $this->getScheme();
$authority = $this->getAuthority();

return ($scheme ? $scheme . ':' : '')
. ($authority ? '//' . $authority : '');
return ($scheme !== '' ? $scheme . ':' : '')
. ($authority !== '' ? '//' . $authority : '');
}
}
12 changes: 12 additions & 0 deletions tests/UriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -597,4 +597,16 @@ public function testRequestURICanContainParams()
);
$this->assertEquals('abc=123', $uri->getQuery());
}

public function testUriDistinguishZeroFromEmptyString()
{
$expected = 'https://0:0@0:1/0?0#0';
$this->assertSame($expected, (string) Uri::createFromString($expected));
}

public function testGetBaseUrlDistinguishZeroFromEmptyString()
{
$expected = 'https://0:0@0:1/0?0#0';
$this->assertSame('https://0:0@0:1', (string) Uri::createFromString($expected)->getBaseUrl());
}
}

0 comments on commit 5924b12

Please sign in to comment.