From eb9bd03ef86e0c453aa034fc9b33dcde278056fc Mon Sep 17 00:00:00 2001 From: Matthew Exon Date: Mon, 29 Jul 2013 10:11:08 +0800 Subject: [PATCH 1/2] If the header returns an absolute path as a redirect, don't simply append the path to the old URL, remove the old absolute path first. For example, original URL: http://www.theregister.co.uk/2013/07/28/birmingham_uni_car_cracker_muzzled_by_lords/print.html Redirect from header: /Print/2013/07/28/birmingham_uni_car_cracker_muzzled_by_lords/ Incorrect result: http://www.theregister.co.uk/2013/07/28/birmingham_uni_car_cracker_muzzled_by_lords/print.html/Print/2013/07/28/birmingham_uni_car_cracker_muzzled_by_lords/ Correct result after this patch: http://www.theregister.co.uk/Print/2013/07/28/birmingham_uni_car_cracker_muzzled_by_lords/ --- include/network.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/network.php b/include/network.php index d2732e0393..d398d8fa0c 100644 --- a/include/network.php +++ b/include/network.php @@ -93,7 +93,7 @@ function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_ $newurl = trim(array_pop($matches)); } if(strpos($newurl,'/') === 0) - $newurl = $url . $newurl; + $newurl = $old_location_info["scheme"]."://".$old_location_info["host"].$newurl; if (filter_var($newurl, FILTER_VALIDATE_URL)) { $redirects++; return fetch_url($newurl,$binary,$redirects,$timeout); From 6a3870556794a5827ebc106d449ba88da6bf489d Mon Sep 17 00:00:00 2001 From: Matthew Exon Date: Mon, 29 Jul 2013 22:33:10 +0800 Subject: [PATCH 2/2] Replicate redirect URL building logic for post requests --- include/network.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/network.php b/include/network.php index d398d8fa0c..a4e0649d08 100644 --- a/include/network.php +++ b/include/network.php @@ -188,7 +188,7 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0) preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches); $newurl = trim(array_pop($matches)); if(strpos($newurl,'/') === 0) - $newurl = $url . $newurl; + $newurl = $old_location_info["scheme"] . "://" . $old_location_info["host"] . $newurl; if (filter_var($newurl, FILTER_VALIDATE_URL)) { $redirects++; return fetch_url($newurl,false,$redirects,$timeout);