From d3ddd6efdbfefa8065a2abcdbcb019b3effd209b Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 5 Feb 2008 23:13:17 +0000 Subject: [PATCH] While we're in there, let's remove a dependency on iconv(). Do the UTF-16 to ASCII merging in the XML checks manually. --- includes/MimeMagic.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/includes/MimeMagic.php b/includes/MimeMagic.php index 8ba992560e..77a306214a 100644 --- a/includes/MimeMagic.php +++ b/includes/MimeMagic.php @@ -479,9 +479,17 @@ class MimeMagic { */ } - if ( $xml_type ) { - if ( $xml_type !== "UTF-8" && $xml_type !== "ASCII" ) { - $head = iconv( $xml_type, "ASCII//IGNORE", $head ); + if( $xml_type == 'UTF-16BE' || $xml_type == 'UTF-16LE' ) { + // Quick and dirty fold down to ASCII! + $pack = array( 'UTF-16BE' => 'n*', 'UTF-16LE' => 'v*' ); + $chars = unpack( $pack[$xml_type], substr( $head, 2 ) ); + $head = ''; + foreach( $chars as $codepoint ) { + if( $codepoint < 128 ) { + $head .= chr( $codepoint ); + } else { + $head .= '?'; + } } } -- 2.20.1