fuel / core

Fuel PHP Framework - The core of the Fuel v1 framework
http://fuelphp.com
813 stars 345 forks source link

Debug::dump() can not dump 'UTF-8' encoding string in 1.5 ? #1296

Closed indigofeather closed 11 years ago

indigofeather commented 11 years ago

in Debug::format() @ line: 194

        elseif (is_string($var))
        {
            $return .= "<i>{$scope}</i> <strong>{$name}</strong> (String): <span style=\"color:#E00000;\">\"".htmlentities($var)."\"</span> (".strlen($var)." characters)\n";
        }

It use htmlentities() to encode the string. If the content of string is 'UTF-8' encoding, it will become unreadable result. Ex:

Debug::dump('中文', 'あ');

result:

Variable #1:
  (String): "中�" (6 characters)

Variable #2:
  (String): "�" (3 characters)

According to http://www.php.net/manual/en/function.htmlentities.php.

I try to fix it:

htmlentities($var, ENT_COMPAT, 'UTF-8')

result is OK:

Variable #1:
  (String): "中文" (6 characters)

Variable #2:
  (String): "あ" (3 characters)
WanWizard commented 11 years ago

I can not reproduce that, it displays fine here. Are you use your mbstring extension is installed and activated?

SDpower commented 11 years ago

in the http://php.net/manual/en/function.htmlentities.php say...

 Like htmlspecialchars(), htmlentities() takes an optional third argument encoding which defines encoding used in conversion. 
If omitted, the default value for this argument is ISO-8859-1 in versions of PHP prior to 5.4.0, and UTF-8 from PHP 5.4.0 onwards. 
Although this argument is technically optional, you are highly encouraged to specify the correct value for your code. 

I recommimt fixed it to be

htmlentities($var, ENT_COMPAT, \Fuel::$encoding);

To suport for php5.4 early version.

WanWizard commented 11 years ago

So you say it goes wrong in PHP 5.3.3 -> 5.4.0? I'll run some more tests.

kenjis commented 11 years ago

@SDpower is right. htmlentities() needs 3rd param in PHP 5.3.

\Security::htmlentities() is better.

indigofeather commented 11 years ago

My PHP version is:

PHP Version 5.3.10-1ubuntu3.5

When I use 5.4, the problem is gone.

rob-bar commented 11 years ago

you should use 5.4, it has some very handy upgrades. I think it's harder when you done some things in 5.4 to go back to 5.3 I hope the fuelphp developers are very aware of those php changes.

Robbie Bardijn Front-end Developer

Mobile: 0472 / 79.88.63 robbie.bardijn@gmail.com

On 24 Jan 2013, at 09:34, Lance He wrote:

My PHP version is:

PHP Version 5.3.10-1ubuntu3.5 When I use 5.4, the problem is gone.

— Reply to this email directly or view it on GitHub.

SDpower commented 11 years ago

@kenjis is better!!

WanWizard commented 11 years ago

Agreed!