Chunked decoding fix from jacobsantos. fixes #8618

git-svn-id: http://svn.automattic.com/wordpress/trunk@10283 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-12-31 03:02:53 +00:00
parent 4acba68cbc
commit c7c9f46367
1 changed files with 5 additions and 11 deletions

View File

@ -412,7 +412,7 @@ class WP_Http {
* @static
*
* @param string $body Body content
* @return bool|string|WP_Error False if not chunked encoded. WP_Error on failure. Chunked decoded body on success.
* @return string Chunked decoded body on success or raw body on failure.
*/
function chunkTransferDecode($body) {
$body = str_replace(array("\r\n", "\r"), "\n", $body);
@ -423,15 +423,12 @@ class WP_Http {
$parsedBody = '';
//$parsedHeaders = array(); Unsupported
$done = false;
do {
while ( true ) {
$hasChunk = (bool) preg_match( '/^([0-9a-f]+)(\s|\n)+/mi', $body, $match );
if ( $hasChunk ) {
if ( empty($match[1]) ) {
if ( empty( $match[1] ) )
return $body;
}
$length = hexdec( $match[1] );
$chunkLength = strlen( $match[0] );
@ -441,15 +438,12 @@ class WP_Http {
$body = ltrim(str_replace(array($match[0], $strBody), '', $body), "\n");
if( "0" == trim($body) ) {
$done = true;
if( "0" == trim($body) )
return $parsedBody; // Ignore footer headers.
break;
}
} else {
return $body;
}
} while ( true === $done );
}
}
}