Chunked decoding fix from jacobsantos. fixes #8618

git-svn-id: https://develop.svn.wordpress.org/trunk@10283 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2008-12-31 03:02:53 +00:00
parent 9563bbea98
commit 44363b9f5f

View File

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