Skip to content

Commit

Permalink
Remove the weird exception handling from string.php. This handling ca…
Browse files Browse the repository at this point in the history
…n cause problems in JArrayHelper::sortObjects due to https://bugs.php.net/bug.php?id=50688.

Iconv throws a notice if there is an illegal character regardless of whether ignore is set so this handling is pointless (and in fact broken since it will always fall back to IGNORE not TRANSLIT). Also, //TRANSLIT,IGNORE not //TRANSLIT//IGNORE will properly both transliterate and ignore.
  • Loading branch information
aaronschmitz committed Aug 17, 2012
1 parent 6ebe9f6 commit ec24a24
Showing 1 changed file with 1 addition and 36 deletions.
37 changes: 1 addition & 36 deletions libraries/joomla/string/string.php
Expand Up @@ -709,23 +709,6 @@ public static function ucwords($str)
return utf8_ucwords($str);
}

/**
* Catch an error and throw an exception.
*
* @param integer $number Error level
* @param string $message Error message
*
* @return void
*
* @link https://bugs.php.net/bug.php?id=48147
*
* @throw ErrorException
*/
private static function _iconvErrorHandler($number, $message)
{
throw new ErrorException($message, 0, $number);
}

/**
* Transcode a string.
*
Expand All @@ -743,25 +726,7 @@ public static function transcode($source, $from_encoding, $to_encoding)
{
if (is_string($source))
{
set_error_handler(array(__CLASS__, '_iconvErrorHandler'), E_NOTICE);
try
{
/*
* "//TRANSLIT//IGNORE" is appended to the $to_encoding to ensure that when iconv comes
* across a character that cannot be represented in the target charset, it can
* be approximated through one or several similarly looking characters or ignored.
*/
$iconv = iconv($from_encoding, $to_encoding . '//TRANSLIT//IGNORE', $source);
}
catch (ErrorException $e)
{
/*
* "//IGNORE" is appended to the $to_encoding to ensure that when iconv comes
* across a character that cannot be represented in the target charset, it is ignored.
*/
$iconv = iconv($from_encoding, $to_encoding . '//IGNORE', $source);
}
restore_error_handler();
$iconv = @iconv($from_encoding, $to_encoding . '//TRANSLIT,IGNORE', $source);
return $iconv;
}

Expand Down

0 comments on commit ec24a24

Please sign in to comment.