Skip to content

Commit 7521906

Browse files
author
Lilli
committed
Added the following patch from the [email protected] mailing list:
http://lists.openidenabled.com/pipermail/dev/attachments/20090109/7e344691/attachment-0001.bin Original Message: ketmar at ketmar.no-ip.org ketmar at ketmar.no-ip.org Fri Jan 9 07:51:35 PST 2009 darcs patch: fix for incomplete URIs in "location" http field (for ... "* fix for incomplete URIs in "location" http field (for technorati and maybe others)" This patch was in the form of a Darcs patch, not a normal patch. So solve this, I applied it to the Darcs repository found on openidenabled, then created a new diff file between the original Darcs repo and the new one (with the patch applied) so that I could apply it to this git repo. Hunks were applied successfully.
1 parent 8b25806 commit 7521906

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

Auth/Yadis/HTTPFetcher.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,40 @@ function URLHasAllowedScheme($url)
115115
/**
116116
* @access private
117117
*/
118-
function _findRedirect($headers)
118+
function _findRedirect($headers, $url)
119119
{
120120
foreach ($headers as $line) {
121121
if (strpos(strtolower($line), "location: ") === 0) {
122122
$parts = explode(" ", $line, 2);
123-
return $parts[1];
123+
$loc = $parts[1];
124+
$ppos = strpos($loc, "://");
125+
if ($ppos === false || $ppos > strpos($loc, "/")) {
126+
/* no host; add it */
127+
$hpos = strpos($url, "://");
128+
$prt = substr($url, 0, $hpos+3);
129+
$url = substr($url, $hpos+3);
130+
if (substr($loc, 0, 1) == "/") {
131+
/* absolute path */
132+
$fspos = strpos($url, "/");
133+
if ($fspos) $loc = $prt.substr($url, 0, $fspos).$loc;
134+
else $loc = $prt.$url.$loc;
135+
} else {
136+
/* relative path */
137+
$pp = $prt;
138+
while (1) {
139+
$xpos = strpos($url, "/");
140+
if ($xpos === false) break;
141+
$apos = strpos($url, "?");
142+
if ($apos !== false && $apos < $xpos) break;
143+
$apos = strpos($url, "&");
144+
if ($apos !== false && $apos < $xpos) break;
145+
$pp .= substr($url, 0, $xpos+1);
146+
$url = substr($url, $xpos+1);
147+
}
148+
$loc = $pp.$loc;
149+
}
150+
}
151+
return $loc;
124152
}
125153
}
126154
return null;

Auth/Yadis/ParanoidHTTPFetcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ function get($url, $extra_headers = null)
142142
}
143143

144144
if (in_array($code, array(301, 302, 303, 307))) {
145-
$url = $this->_findRedirect($headers);
145+
$url = $this->_findRedirect($headers, $url);
146146
$redir = true;
147147
} else {
148148
$redir = false;

Auth/Yadis/PlainHTTPFetcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ function get($url, $extra_headers = null)
122122
$code = $http_code[1];
123123

124124
if (in_array($code, array('301', '302'))) {
125-
$url = $this->_findRedirect($headers);
125+
$url = $this->_findRedirect($headers, $url);
126126
$redir = true;
127127
} else {
128128
$redir = false;

0 commit comments

Comments
 (0)