Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removeEmptyPairs(): undocumented behavior change between v6 and v7 #133

Closed
davidrans opened this issue Mar 22, 2024 · 2 comments
Closed
Assignees
Labels
bug Something isn't working easy pick Issue that can be easily fix

Comments

@davidrans
Copy link
Contributor

davidrans commented Mar 22, 2024

Bug Report

Behavior in version 6.8:

$removeEmptyPairs = function(string $str): ?string {
   $uri = Uri\Http::createFromString($str);         
   $new = UriModifier::removeEmptyPairs($uri);      
   return $new->getQuery();                         
};
echo $removeEmptyPairs('https://a.b/c?d='); // ""
echo $removeEmptyPairs('https://a.b/c?=d'); // ""
echo $removeEmptyPairs('https://a.b/c?='); //  ""

Behavior in 7.4:

echo $removeEmptyPairs('https://a.b/c?d='); // "d="
echo $removeEmptyPairs('https://a.b/c?=d'); // "=d"
echo $removeEmptyPairs('https://a.b/c?='); //  "="

Was this behavior change intentional?

@nyamsprod nyamsprod self-assigned this Mar 23, 2024
@nyamsprod nyamsprod added bug Something isn't working easy pick Issue that can be easily fix labels Mar 23, 2024
@nyamsprod
Copy link
Member

@davidrans thanks for the bug report. It is indeed a bug caused by the re-implementation of the now deprecated class UriModifier.

I used the wrong method while re-implementing the UriModifier class instead of using

    /**
     * Remove empty pairs from the URL query component.
     *
     * A pair is considered empty if it's name is the empty string
     * and its value is either the empty string or the null value
     */
    public static function removeEmptyPairs(Psr7UriInterface|UriInterface $uri): Psr7UriInterface|UriInterface
    {
+ return Modifier::from($uri)->removeEmptyQueryPairs()->getUri();
- return Modifier::from($uri)->removeQueryPairsByKey()->getUri();
    }

the fix will be release ASAP via a patch version. In the meantime I would suggest upgrading the code to use the new way as the behaviour does exists in version 7. People using the new API do not face this bug.

@davidrans
Copy link
Contributor Author

I appreciate the quick response and fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working easy pick Issue that can be easily fix
Projects
None yet
Development

No branches or pull requests

2 participants