Switch WP_HTTP over to using the mbstring.func_overload helper functions. This change moves the check from within the Streaming-handling function to wrap the individual request, this fixes it for both cURL and Streams and any future changes to the transports which use strlen() on binary data. See #25259 See #16057

Built from https://develop.svn.wordpress.org/trunk@25348


git-svn-id: http://core.svn.wordpress.org/trunk@25310 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dion Hulse 2013-09-11 08:13:10 +00:00
parent 83ebc727e8
commit c93eb27bb2

View File

@ -166,6 +166,9 @@ class WP_Http {
// Construct Cookie: header if any cookies are set
WP_Http::buildCookieHeader( $r );
// Avoid issues where mbstring.func_overload is enabled
mbstring_binary_safe_encoding();
if ( ! isset( $r['headers']['Accept-Encoding'] ) ) {
if ( $encoding = WP_Http_Encoding::accept_encoding( $url, $r ) )
$r['headers']['Accept-Encoding'] = $encoding;
@ -187,6 +190,9 @@ class WP_Http {
}
$response = $this->_dispatch_request( $url, $r );
reset_mbstring_encoding();
if ( is_wp_error( $response ) )
return $response;
@ -1319,11 +1325,6 @@ class WP_Http_Curl {
* @return int
*/
private function stream_body( $handle, $data ) {
if ( function_exists( 'ini_get' ) && ( ini_get( 'mbstring.func_overload' ) & 2 ) && function_exists( 'mb_internal_encoding' ) ) {
$mb_encoding = mb_internal_encoding();
mb_internal_encoding( 'ISO-8859-1' );
}
$data_length = strlen( $data );
if ( $this->max_body_length && ( strlen( $this->body ) + $data_length ) > $this->max_body_length )
@ -1336,9 +1337,6 @@ class WP_Http_Curl {
$bytes_written = $data_length;
}
if ( isset( $mb_encoding ) )
mb_internal_encoding( $mb_encoding );
// Upon event of this function returning less than strlen( $data ) curl will error with CURLE_WRITE_ERROR
return $bytes_written;
}