diff --git a/composer.json b/composer.json index a6df5a1..ed505f1 100644 --- a/composer.json +++ b/composer.json @@ -46,5 +46,13 @@ "psr-4": { "Slim\\Tests\\Http\\": "tests/" } + }, + "scripts": { + "test": [ + "@phpunit", + "@phpcs" + ], + "phpunit": "php vendor/bin/phpunit", + "phpcs": "php vendor/bin/phpcs" } } diff --git a/src/Uri.php b/src/Uri.php index c6f8ef1..6712a5a 100644 --- a/src/Uri.php +++ b/src/Uri.php @@ -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 : ''); @@ -789,7 +789,7 @@ public function getBaseUrl() $scheme = $this->getScheme(); $authority = $this->getAuthority(); - return ($scheme ? $scheme . ':' : '') - . ($authority ? '//' . $authority : ''); + return ($scheme !== '' ? $scheme . ':' : '') + . ($authority !== '' ? '//' . $authority : ''); } } diff --git a/tests/UriTest.php b/tests/UriTest.php index 1c717bb..0609169 100644 --- a/tests/UriTest.php +++ b/tests/UriTest.php @@ -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()); + } }