Skip to content

Commit 1589b3b

Browse files
nyamsprodakrabat
authored andcommitted
forward port to slimphp/Slim#2449
1 parent 5139884 commit 1589b3b

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

composer.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,13 @@
4646
"psr-4": {
4747
"Slim\\Tests\\Http\\": "tests/"
4848
}
49+
},
50+
"scripts": {
51+
"test": [
52+
"@phpunit",
53+
"@phpcs"
54+
],
55+
"phpunit": "php vendor/bin/phpunit",
56+
"phpcs": "php vendor/bin/phpcs"
4957
}
5058
}

src/Uri.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -768,8 +768,8 @@ public function __toString()
768768

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

771-
return ($scheme ? $scheme . ':' : '')
772-
. ($authority ? '//' . $authority : '')
771+
return ($scheme !== '' ? $scheme . ':' : '')
772+
. ($authority !== '' ? '//' . $authority : '')
773773
. $path
774774
. ($query !== '' ? '?' . $query : '')
775775
. ($fragment !== '' ? '#' . $fragment : '');
@@ -789,7 +789,7 @@ public function getBaseUrl()
789789
$scheme = $this->getScheme();
790790
$authority = $this->getAuthority();
791791

792-
return ($scheme ? $scheme . ':' : '')
793-
. ($authority ? '//' . $authority : '');
792+
return ($scheme !== '' ? $scheme . ':' : '')
793+
. ($authority !== '' ? '//' . $authority : '');
794794
}
795795
}

tests/UriTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,4 +597,16 @@ public function testRequestURICanContainParams()
597597
);
598598
$this->assertEquals('abc=123', $uri->getQuery());
599599
}
600+
601+
public function testUriDistinguishZeroFromEmptyString()
602+
{
603+
$expected = 'https://0:0@0:1/0?0#0';
604+
$this->assertSame($expected, (string) Uri::createFromString($expected));
605+
}
606+
607+
public function testGetBaseUrlDistinguishZeroFromEmptyString()
608+
{
609+
$expected = 'https://0:0@0:1/0?0#0';
610+
$this->assertSame('https://0:0@0:1', (string) Uri::createFromString($expected)->getBaseUrl());
611+
}
600612
}

0 commit comments

Comments
 (0)