diff --git a/spec/EcPhp/CasLib/Utils/UriSpec.php b/spec/EcPhp/CasLib/Utils/UriSpec.php index 00bf76a..4738e9c 100644 --- a/spec/EcPhp/CasLib/Utils/UriSpec.php +++ b/spec/EcPhp/CasLib/Utils/UriSpec.php @@ -163,6 +163,22 @@ public function it_can_remove_parameters() $this::removeParams($uri, 'param3', 'param2', 'param1') ->__toString() ->shouldReturn('http://host/path#fragment'); + + $url = 'http://host/path?param1=param1¶m2=param2¶m3=param3#fragment'; + + $uri = new \Nyholm\Psr7\Uri($url); + + $this::removeParams($uri, 'param1', 'param2', 'param4') + ->__toString() + ->shouldReturn('http://host/path?param3=param3#fragment'); + + $url = 'http://host/path?param1=param1¶m2=param2¶m3=param3#fragment'; + + $uri = new \Nyholm\Psr7\Uri($url); + + $this::removeParams($uri) + ->__toString() + ->shouldReturn($url); } public function it_can_set_multiple_params_at_the_same_time() diff --git a/src/Utils/Uri.php b/src/Utils/Uri.php index ff3ebc5..70d0430 100644 --- a/src/Utils/Uri.php +++ b/src/Utils/Uri.php @@ -58,12 +58,8 @@ public static function hasParams(UriInterface $uri, string ...$keys): bool */ public static function removeParams(UriInterface $uri, string ...$keys): UriInterface { - foreach ($keys as $key) { - if (false === self::hasParams($uri, $key)) { - continue; - } - - $uri = $uri->withQuery( + return $uri + ->withQuery( http_build_query( array_diff_key( self::getParams($uri), @@ -71,9 +67,6 @@ public static function removeParams(UriInterface $uri, string ...$keys): UriInte ) ) ); - } - - return $uri; } /**