Skip to content

Commit

Permalink
[BUGFIX] Allow PSR-7 Uris to allow no port at all
Browse files Browse the repository at this point in the history
In order to set a PSR-7 based uri to the default port
the specs allow to set $uri->withPort(null) but our
tests and implementation restrict that.

Resolves: #84518
Releases: master, 8.7
Change-Id: Ic2c3d70fca35a767c7ed9d324eb93b30c66bbd3e
Reviewed-on: https://review.typo3.org/56416
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Mathias Brodala <mbrodala@pagemachine.de>
Tested-by: Mathias Brodala <mbrodala@pagemachine.de>
Reviewed-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Tested-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
  • Loading branch information
bmack authored and georgringer committed Mar 22, 2018
1 parent 18aaf1b commit 971ff29
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
16 changes: 9 additions & 7 deletions typo3/sysext/core/Classes/Http/Uri.php
Expand Up @@ -434,14 +434,16 @@ public function withHost($host)
*/
public function withPort($port)
{
if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($port) === false) {
$argumentType = is_object($port) ? get_class($port) : gettype($port);
throw new \InvalidArgumentException('Invalid port "' . $argumentType . '" specified, must be an integer.', 1436717324);
}
if ($port !== null) {
if (\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($port) === false) {
$argumentType = is_object($port) ? get_class($port) : gettype($port);
throw new \InvalidArgumentException('Invalid port "' . $argumentType . '" specified, must be an integer.', 1436717324);
}

$port = (int)$port;
if ($port < 1 || $port > 65535) {
throw new \InvalidArgumentException('Invalid port "' . $port . '" specified, must be a valid TCP/UDP port.', 1436717326);
$port = (int)$port;
if ($port < 1 || $port > 65535) {
throw new \InvalidArgumentException('Invalid port "' . $port . '" specified, must be a valid TCP/UDP port.', 1436717326);
}
}

$clonedObject = clone $this;
Expand Down
13 changes: 12 additions & 1 deletion typo3/sysext/core/Tests/Unit/Http/UriTest.php
Expand Up @@ -97,6 +97,18 @@ public function withHostReturnsNewInstanceWithProvidedHost()
$this->assertEquals('https://user:pass@framework.zend.com:3001/foo?bar=baz#quz', (string) $new);
}

/**
* @test
*/
public function withPortAndNullValueReturnsInstanceWithProvidedPort()
{
$uri = new Uri('https://user:pass@local.example.com:3001/foo?bar=baz#quz');
$new = $uri->withPort(null);
$this->assertEquals(
'https://user:pass@local.example.com/foo?bar=baz#quz',
(string) $new
);
}
/**
* @return array
*/
Expand Down Expand Up @@ -130,7 +142,6 @@ public function withPortReturnsNewInstanceWithProvidedPort($port)
public function invalidPortsDataProviderType()
{
return [
'null' => [null],
'false' => [false],
'string' => ['string'],
'array' => [[3000]],
Expand Down

0 comments on commit 971ff29

Please sign in to comment.