From aefea5b855d2654472794fe903d55d9862de246c Mon Sep 17 00:00:00 2001 From: ignace nyamagana butera Date: Sat, 23 Mar 2024 08:18:00 +0100 Subject: [PATCH] Bug fix #133 --- components/CHANGELOG.md | 19 +++++++++++++++++++ components/UriModifier.php | 2 +- components/UriModifierTest.php | 29 +++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 components/UriModifierTest.php diff --git a/components/CHANGELOG.md b/components/CHANGELOG.md index 7577dd97..128c0754 100644 --- a/components/CHANGELOG.md +++ b/components/CHANGELOG.md @@ -2,6 +2,25 @@ All Notable changes to `League\Uri\Components` will be documented in this file +## [Next](https://github.com/thephpleague/uri-components/compare/7.4.0...master) - TBD + +### Added + +- None + +### Fixed + +- Fix package to avoid PHP8.4 deprecation warnings +- Bug Fix `removeEmptyPairs` [#133](https://github.com/thephpleague/uri-src/issues/133) + +### Deprecated + +- None + +### Removed + +- None + ## [7.4.0](https://github.com/thephpleague/uri-components/compare/7.3.0...7.4.0) - 2023-12-01 ### Added diff --git a/components/UriModifier.php b/components/UriModifier.php index f4c83715..51791f83 100644 --- a/components/UriModifier.php +++ b/components/UriModifier.php @@ -65,7 +65,7 @@ public static function removePairs(Psr7UriInterface|UriInterface $uri, string .. */ public static function removeEmptyPairs(Psr7UriInterface|UriInterface $uri): Psr7UriInterface|UriInterface { - return Modifier::from($uri)->removeQueryPairsByKey()->getUri(); + return Modifier::from($uri)->removeEmptyQueryPairs()->getUri(); } /** diff --git a/components/UriModifierTest.php b/components/UriModifierTest.php new file mode 100644 index 00000000..0d5ec37e --- /dev/null +++ b/components/UriModifierTest.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace League\Uri; + +use PHPUnit\Framework\TestCase; + +final class UriModifierTest extends TestCase +{ + /** @test */ + public function it_will_remove_empty_pairs_fix_issue_133(): void + { + $removeEmptyPairs = fn (string $str): ?string => UriModifier::removeEmptyPairs(Http::createFromString($str))->getQuery(); /* @phpstan-ignore-line */ + + self::assertSame('', $removeEmptyPairs('https://a.b/c?d=')); + self::assertSame('', $removeEmptyPairs('https://a.b/c?=d')); + self::assertSame('', $removeEmptyPairs('https://a.b/c?=')); + } +}