Skip to content

Commit

Permalink
Merge branch 'hotfix/response_substr' of https://github.com/sasezaki/zf2
Browse files Browse the repository at this point in the history
 into hotfix/response-multibyte
  • Loading branch information
weierophinney committed Apr 9, 2012
2 parents 293d1f0 + 728fc1c commit bb50222
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions library/Zend/Http/Response.php
Expand Up @@ -485,30 +485,17 @@ protected function decodeChunkedBody($body)
{
$decBody = '';

// If mbstring overloads substr and strlen functions, we have to
// override it's internal encoding
if (function_exists('mb_internal_encoding') &&
((int) ini_get('mbstring.func_overload')) & 2) {

$mbIntEnc = mb_internal_encoding();
mb_internal_encoding('ASCII');
}

while (trim($body)) {
if (! preg_match("/^([\da-fA-F]+)[^\r\n]*\r\n/sm", $body, $m)) {
throw new Exception\RuntimeException("Error parsing body - doesn't seem to be a chunked message");
}

$length = hexdec(trim($m[1]));
$cut = strlen($m[0]);
$cut = static::strlen($m[0]);
$decBody .= substr($body, $cut, $length);
$body = substr($body, $cut + $length + 2);
}

if (isset($mbIntEnc)) {
mb_internal_encoding($mbIntEnc);
}

return $decBody;
}

Expand Down Expand Up @@ -567,4 +554,19 @@ protected function decodeDeflate($body)
}
}

/**
* Returns length of binary string in bytes
*
* @param string $str
* @return int the string length
*/
static public function strlen($str)
{
if (function_exists('mb_internal_encoding') &&
(((int)ini_get('mbstring.func_overload')) & 2)) {
return mb_strlen($str, '8bit');
} else {
return strlen($str);
}
}
}

0 comments on commit bb50222

Please sign in to comment.