DyegoAV / slimstat

Automatically exported from code.google.com/p/slimstat
GNU General Public License v2.0
1 stars 0 forks source link

Iconv #29

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.return iconv( $encoding, 'UTF-8', $_str );

What is the expected output? What do you see instead?
'index | d_fens' => '' (probably 0b or FALSE) inserts a NULL into the DB
for title (possibly other fields too).

What version of the product are you using? On what operating system?
PHP 5.2.4-2ubuntu5.10 with Suhosin-Patch 0.9.6.2 and Solaris

Please provide any additional information below.
http://www.php.net/manual/en/function.iconv.php
Numerous problems relating to this.

Personally I think it's down to Solaris own libiconv since I think it might
be missing transliteration as converting with iconv seems to result in
blank strings. 

I changed the block for encoding to look like this, seem's to work. I dont
mind if it turns out to be a wontfix since it might be outside slimstats
own issues.

                $encoding = mb_detect_encoding( $_str );
                if ( strtoupper( $encoding ) == 'UTF-8' ) {
                        return $_str;
                } else {
                        $translation = iconv( $encoding, 'UTF-8', $_str );
                        if ( $translation ) {
                                return $translation;
                        } else {
                                return utf8_encode( $_str );
                        }
                }

Original issue reported on code.google.com by dfens...@gmail.com on 26 Jan 2010 at 6:20

GoogleCodeExporter commented 9 years ago
Do you know what the $encoding variable is getting set to? If the encoding is 
unknown
then perhaps it should just return the original string at that point.

Original comment by step...@wettone.com on 26 Jan 2010 at 8:49

GoogleCodeExporter commented 9 years ago
Like this:

    function utf8_encode( $_str ) {
        $encoding = mb_detect_encoding( $_str );
        if ( $encoding == false || strtoupper( $encoding ) == 'UTF-8' ) {
            return $_str;
        } else {
            return iconv( $encoding, 'UTF-8', $_str );
        }
    }

Original comment by step...@wettone.com on 26 Jan 2010 at 9:12

GoogleCodeExporter commented 9 years ago
$encoding is set to ASCII

Original comment by dfens...@gmail.com on 27 Jan 2010 at 9:16

GoogleCodeExporter commented 9 years ago
In which case we can return at that point, because ASCII is a subset of UTF-8.

Give this a try:

    function utf8_encode( $_str ) {
        $encoding = mb_detect_encoding( $_str );
        if ( $encoding == false || strtoupper( $encoding ) == 'UTF-8' || strtoupper(
$encoding ) == 'ASCII' ) {
            return $_str;
        } else {
            return iconv( $encoding, 'UTF-8', $_str );
        }
    }

Original comment by step...@wettone.com on 27 Jan 2010 at 9:20

GoogleCodeExporter commented 9 years ago
Yup that seems to work. (Lacking test cases though so I'm not sure if it covers 
it)

Original comment by dfens...@gmail.com on 27 Jan 2010 at 11:08

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r83.

Original comment by step...@wettone.com on 28 Jan 2010 at 3:31