Nyholm / psr7

A super lightweight PSR-7 implementation
MIT License
1.18k stars 76 forks source link

Filter Uri->withUserInfo() input #206

Closed mabar closed 1 year ago

mabar commented 1 year ago

I have a login, which contains @ in username and password. User info with this character is currently not encoded. I think there should be a filterUserInfo() method to correctly encode input as other with* methods do.

I checked other popular implementations and all of them do that:

Most accurate seem to be guzzle and laminas implementations which do this:

    private function filterUserInfo($userInfo): string
    {
        if (!is_string($userInfo)) {
            throw new \InvalidArgumentException('User info must be a string');
        }

        return preg_replace_callback(
            '/(?:[^%' . self::CHAR_UNRESERVED . self::CHAR_SUB_DELIMS . ']+|%(?![A-Fa-f0-9]{2}))/',
            [$this, 'rawurlencodeMatchZero'],
            $userInfo
        );
    }

Only difference is in laminas/laminas-diactoros which also checks for invalid UTF-8 characters

boesing commented 1 year ago

Hey there,

thanks to http-plug/discovery, I stumbled over this issue as well. We are unable to connect to our elasticsearch anymore as some 3rd-party dependency depends on this package which has a higher priority in that discovery thing.

Is there anything I can do to move this forward?

nicolas-grekas commented 1 year ago

It could be worth contributing this case to https://github.com/php-http/psr7-integration-tests Could you give it a try maybe @boesing or @mabar ?