Discussion:
[Phpgroupware-cvs] [20896] Bug fix : check for already encoded utf8 stuff ...
Sigurd Nes
2009-11-25 17:50:08 UTC
Permalink
Revision: 20896
http://svn.sv.gnu.org/viewvc/?view=rev&root=phpgroupware&revision=20896
Author: Caeies
Date: 2009-11-25 16:35:37 +0000 (Wed, 25 Nov 2009)
-----------
Bug fix : check for already encoded utf8 stuff ... instead of forcing it in all cases since utf8_encode(utf8_encode(X)) != utf_8_encode(X) if X is not pure ascii
--------------
modules/email/trunk/inc/class.mail_msg_base.inc.php
Modified: modules/email/trunk/inc/class.mail_msg_base.inc.php
===================================================================
--- modules/email/trunk/inc/class.mail_msg_base.inc.php 2009-11-25 16:06:05 UTC (rev 20895)
+++ modules/email/trunk/inc/class.mail_msg_base.inc.php 2009-11-25 16:35:37 UTC (rev 20896)
@@ -4437,7 +4437,7 @@
*/
function ascii2utf($text = '')
{
- if ($text == utf8_encode($text))
+ if ((function_exists('mb_detect_encoding') && mb_detect_encoding($text) == 'UTF-8'))
{
return $text;
}
Hi Caeies,

That one didn't work (for me).
the mb_detect_encoding($text) is detecting the text as utf-8 even if it
is ISO-8859-1

Please test.

I'm using PHP Version 5.3.1 with default settings:


mbstring

Multibyte Support enabled
Multibyte string engine libmbfl
HTTP input encoding translation disabled


mbstring extension makes use of "streamable kanji code filter and
converter", which is distributed under the GNU Lesser General Public
License version 2.1.


Multibyte (japanese) regex support enabled
Multibyte regex (oniguruma) backtrack check On
Multibyte regex (oniguruma) version 4.7.1


Directive Local Value Master Value
mbstring.detect_order /no value/ /no value/
mbstring.encoding_translation Off Off
mbstring.func_overload 0 0
mbstring.http_input pass pass
mbstring.http_output pass pass
mbstring.http_output_conv_mimetypes ^(text/|application/xhtml\+xml)
^(text/|application/xhtml\+xml)
mbstring.internal_encoding /no value/ /no value/
mbstring.language neutral neutral
mbstring.strict_detection Off Off
mbstring.substitute_character /no value/ /no value/



Regards

Sigurd
Benoit Hamet
2009-11-25 19:00:33 UTC
Permalink
Hi Sigurd,
Post by Sigurd Nes
That one didn't work (for me).
the mb_detect_encoding($text) is detecting the text as utf-8 even if it
is ISO-8859-1
This is a problem in your configuration of php. Anyway, I commit a fix
that should work in most configuration. Note that our non ISO-8859-1
users will have problem with your code, since I'm not sure that
utf8_encode is able to take their charset into account ...

Regards,

Caeies.
Post by Sigurd Nes
Please test.
mbstring
Multibyte Support enabled
Multibyte string engine libmbfl
HTTP input encoding translation disabled
mbstring extension makes use of "streamable kanji code filter and
converter", which is distributed under the GNU Lesser General Public
License version 2.1.
Multibyte (japanese) regex support enabled
Multibyte regex (oniguruma) backtrack check On
Multibyte regex (oniguruma) version 4.7.1
Directive Local Value Master Value
mbstring.detect_order /no value/ /no value/
mbstring.encoding_translation Off Off
mbstring.func_overload 0 0
mbstring.http_input pass pass
mbstring.http_output pass pass
mbstring.http_output_conv_mimetypes ^(text/|application/xhtml\+xml)
^(text/|application/xhtml\+xml)
mbstring.internal_encoding /no value/ /no value/
mbstring.language neutral neutral
mbstring.strict_detection Off Off
mbstring.substitute_character /no value/ /no value/
Regards
Sigurd
------------------------------------------------------------------------
_______________________________________________
phpGroupWare-developers mailing list
http://lists.gnu.org/mailman/listinfo/phpgroupware-developers
Sigurd Nes
2009-11-25 21:07:50 UTC
Permalink
Post by Benoit Hamet
Hi Sigurd,
Post by Sigurd Nes
That one didn't work (for me).
the mb_detect_encoding($text) is detecting the text as utf-8 even if it
is ISO-8859-1
This is a problem in your configuration of php. Anyway, I commit a fix
that should work in most configuration. Note that our non ISO-8859-1
users will have problem with your code, since I'm not sure that
utf8_encode is able to take their charset into account ...
Great - it works fine

Thanks

Sigurd

Benoit Hamet
2009-11-25 19:27:52 UTC
Permalink
Post by Sigurd Nes
Revision: 20896
http://svn.sv.gnu.org/viewvc/?view=rev&root=phpgroupware&revision=20896
Author: Caeies
Date: 2009-11-25 16:35:37 +0000 (Wed, 25 Nov 2009)
-----------
Bug fix : check for already encoded utf8 stuff ... instead of forcing
it in all cases since utf8_encode(utf8_encode(X)) != utf_8_encode(X)
if X is not pure ascii
--------------
modules/email/trunk/inc/class.mail_msg_base.inc.php
Modified: modules/email/trunk/inc/class.mail_msg_base.inc.php
===================================================================
--- modules/email/trunk/inc/class.mail_msg_base.inc.php 2009-11-25
16:06:05 UTC (rev 20895)
+++ modules/email/trunk/inc/class.mail_msg_base.inc.php 2009-11-25
16:35:37 UTC (rev 20896)
@@ -4437,7 +4437,7 @@
*/
function ascii2utf($text = '')
{
- if ($text == utf8_encode($text))
+ if ((function_exists('mb_detect_encoding') &&
mb_detect_encoding($text) == 'UTF-8'))
{
return $text;
}
Hi Caeies,
That one didn't work (for me).
the mb_detect_encoding($text) is detecting the text as utf-8 even if it
is ISO-8859-1
Please test.
You too.
if ($text == utf8_encode($text)) is a non-sense with already utf8 non
ascii-only text ...

And I didn't put any comment on that in the commit ... But if you want
me to insist on the garbage code on the public list, I will be happy to
do so.

Regards,

Caeies.
Loading...