From e91dcf8fac5655337295449d99e78daf85fd8a42 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Sun, 18 Aug 2013 08:18:10 +0000 Subject: [PATCH] WP_HTTP: Curl: When using Stream-to-file on servers using mbstring.func_overload ensure that the file is written out correctly. Props DrProtocols. See #25061 for trunk Built from https://develop.svn.wordpress.org/trunk@25051 git-svn-id: http://core.svn.wordpress.org/trunk@25038 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-http.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/wp-includes/class-http.php b/wp-includes/class-http.php index 86bf845c0b..9b490b0dc8 100644 --- a/wp-includes/class-http.php +++ b/wp-includes/class-http.php @@ -1394,6 +1394,11 @@ 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' ); + } + if ( $this->max_body_length && ( strlen( $this->body ) + strlen( $data ) ) > $this->max_body_length ) $data = substr( $data, 0, ( $this->max_body_length - strlen( $this->body ) ) ); @@ -1402,7 +1407,12 @@ class WP_Http_Curl { else $this->body .= $data; - return strlen( $data ); + $data_length = strlen( $data ); + + if ( isset( $mb_encoding ) ) + mb_internal_encoding( $mb_encoding ); + + return $data_length; } /**