php-proxy icon indicating copy to clipboard operation
php-proxy copied to clipboard

Improve rel2abs

Open khavishbhundoo opened this issue 8 years ago • 1 comments

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

khavishbhundoo avatar Jul 12 '17 13:07 khavishbhundoo

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";

DigiLive avatar Jan 15 '20 10:01 DigiLive