simple-php-router icon indicating copy to clipboard operation
simple-php-router copied to clipboard

urlencoding issue with non-ASCII chars in request-uri header

Open DeveloperMarius opened this issue 3 years ago • 0 comments

Hello,

this is the fix for the issue #613.

The issue

The problem was that the route /κκκκ was not accessible. After some debugging, I found out that the complete url was urlencoded and then compared to the url of the route. /%CE%BA%CE%BA%CE%BA%CE%BA is not /κκκκ. When you urldecode /%CE%BA%CE%BA%CE%BA%CE%BA you get /\xce\xba\xce\xba\xce\xba\xce\xba/ (UTF-8) which is equals to /κκκκ.

So why is the url urlencoded?

A Stackoverflow post brought to my attention that the browser urlencodes special chars and passes them using the request-uri header.

The solution

I changed $this->setUrl(new Url($this->getFirstHeader(['unencoded-url', 'request-uri']))); to

$url = $this->getHeader('unencoded-url');
        if($url !== null){
            $this->setUrl(new Url($url));
        }else{
            $this->setUrl(new Url(urldecode($this->getHeader('request-uri'))));
        }

so that the header will now be correctly urldecoded.

~ Marius

DeveloperMarius avatar Mar 01 '22 14:03 DeveloperMarius