Athlon1600 / php-proxy

A web proxy script written in PHP and built as an alternative to Glype.
https://www.php-proxy.com
MIT License
296 stars 158 forks source link

Improve rel2abs #71

Open khavishbhundoo opened 7 years ago

khavishbhundoo commented 7 years ago

The function used to convert relative url into absolute ones fails several test cases.

rel2abs failure: http://a/b/c/. instead of http://a/b/c/ rel2abs failure: http://a/b/c/.. instead of http://a/b/ rel2abs failure: http://a/b/.. instead of http://a/ rel2abs failure: http://a/b/c/g/. instead of http://a/b/c/g/ rel2abs failure: http://a/b/c/g?y/x instead of http://a/b/c/g?y/./x rel2abs failure: http://a/b/c/x instead of http://a/b/c/g?y/../x rel2abs failure: http://a/b/c/g#s/x instead of http://a/b/c/g#s/./x rel2abs failure: http://a/b/c/x instead of http://a/b/c/g#s/../x rel2abs failure: http://a/b/c/g/ instead of http://a/b/g/ rel2abs: successes -> 29, failures => 9, elapsed time: 0.00034500000000004 url_to_absolute failure: http://a/b/c instead of http://a/b/c/ url_to_absolute failure: http://a/b instead of http://a/b/ url_to_absolute failure: http://a/b/c/g instead of http://a/b/c/g/ url_to_absolute failure: instead of http://a/b/c/ө/ url_to_absolute failure: http://a/b/c/g/ instead of http://a/b/g/ url_to_absolute: successes -> 33, failures => 5, elapsed time: 0.001218 phpuri failure: http://a/b/c/g/ instead of http://a/b/g/ phpuri: successes -> 37, failures => 1, elapsed time: 0.00063600000000003 net_url2 failure: http://a/b/c/%D3%A9/ instead of http://a/b/c/ө/ net_url2 failure: http://a/b/c/g/ instead of http://a/b/g/ net_url2: successes -> 36, failures => 2, elapsed time: 0.001313

I suggest using phpuri instead.The test page can be downloaded here

DigiLive commented 4 years ago

Also when using a portnumber, it isn't taken into account at the rel2abs function. E.g: https://mySite.com:2222/Hello becomes https://mySite.com/Hello

I think https://github.com/Athlon1600/php-proxy/blob/dc8266db597c5b5e88a3ea5a8dbec00d20abe60a/src/helpers.php#L208

should be something like

    $abs = $host;
    if ($port != '') {
        $abs .= ":$port";
    }
    $abs .= "/$path/$rel";