From c93eb27bb2475d928faa643a5a157c8848e0d3cf Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Wed, 11 Sep 2013 08:13:10 +0000 Subject: [PATCH] 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 --- wp-includes/class-http.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/wp-includes/class-http.php b/wp-includes/class-http.php index 204a38acaa..44b6b01310 100644 --- a/wp-includes/class-http.php +++ b/wp-includes/class-http.php @@ -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; }