diff --git a/typo3/sysext/core/Classes/Http/Uri.php b/typo3/sysext/core/Classes/Http/Uri.php index 7d1b2740ac27..0bc59af819ea 100644 --- a/typo3/sysext/core/Classes/Http/Uri.php +++ b/typo3/sysext/core/Classes/Http/Uri.php @@ -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; diff --git a/typo3/sysext/core/Tests/Unit/Http/UriTest.php b/typo3/sysext/core/Tests/Unit/Http/UriTest.php index 85dd41bc0c7f..fb26993c7853 100644 --- a/typo3/sysext/core/Tests/Unit/Http/UriTest.php +++ b/typo3/sysext/core/Tests/Unit/Http/UriTest.php @@ -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 */ @@ -130,7 +142,6 @@ public function withPortReturnsNewInstanceWithProvidedPort($port) public function invalidPortsDataProviderType() { return [ - 'null' => [null], 'false' => [false], 'string' => ['string'], 'array' => [[3000]],