php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46455 htmlentities() does not use default_charset or setlocale values
Submitted: 2008-11-01 17:16 UTC Modified: 2008-11-01 22:13 UTC
From: hostmaster at uuism dot net Assigned:
Status: Not a bug Package: *Languages/Translation
PHP Version: 5.2CVS-2008-11-01 (snap) OS: Fedora Core 4
Private report: No CVE-ID: None
 [2008-11-01 17:16 UTC] hostmaster at uuism dot net
Description:
------------
The function htmlentities() appears to ignore the default_charset value in the php.ini file or the INI section of test scripts.

I can't find any indication in the PHP Manual that htmlentities() is supposed to use the value for default_charset.

This problem produces failure in the following tests:

htmlentities() test 10 (default_charset / cp1252) [ext/standard/tests/strings/htmlentities10.phpt]
htmlentities() test 11 (default_charset / ISO-8859-15) [ext/standard/tests/strings/htmlentities11.phpt]
htmlentities() test 13 (default_charset / EUC-JP) [ext/standard/tests/strings/htmlentities13.phpt]

If I change the htmlentities() statement to htmlentities("special characters", ENT_QUOTES, 'string') where string is cp1252, ISO-8859-15, and ISO-8859-15, respectively, the tests pass.

The same kind of problem occurs with htmlentities() after the setlocale() command. 

I can't find any indication in the PHP Manual that htmlentities() is supposed to use the value from the setlocale() command.

This variation of the problem causes these tests to fail:

htmlentities() test 2 (setlocale / fr_FR.ISO-8859-15) [ext/standard/tests/strings/htmlentities02.phpt] (warn: possibly braind
ead libc)
htmlentities() test 4 (setlocale / ja_JP.EUC-JP) [ext/standard/tests/strings/htmlentities04.phpt] (warn: possibly braindead l
ibc)
htmlentities() test 15 (setlocale / KOI8-R) [ext/standard/tests/strings/htmlentities15.phpt] (warn: possibly braindead libc)

If I change the htmlentities() statement to htmlentities("special characters", ENT_QUOTES, 'string') where string is ISO-8859-15, If I change the htmlentities() statement to htmlentities("special characters", ENT_QUOTES, 'string') where string is cp1252, ISO-8859-15, and KOI8-R, respectively, the tests pass.



Reproduce code:
---------------
<?php
$result = (bool)setlocale(LC_CTYPE, "fr_FR.ISO-8859-15", "fr_FR.ISO8859-15", 'fr_FR@euro');
if (!$result) {
        die("skip setlocale() failed\n");
}
echo "warn possibly braindead libc\n";
?>
--INI--
output_handler=
default_charset=
mbstring.internal_encoding=none
--FILE--
<?php
        setlocale(LC_CTYPE, "fr_FR.ISO-8859-15", "fr_FR.ISO8859-15", 'fr_FR@euro');
        var_dump(htmlentities("\xbc\xbd\xbe", ENT_QUOTES, 'ISO-8859-15'));
?>


Expected result:
----------------
string(20) "&OElig;&oelig;&Yuml;"


Actual result:
--------------
string(24) "&frac14;&frac12;&frac34;"


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-11-01 20:38 UTC] jani@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 [2008-11-01 22:13 UTC] hostmaster at uuism dot net
Let me express this a different way.

In my php.ini file, I have:

default_charset = "iso-8859-15"

My code is:

<?php
        print ini_get('default_charset')."\n";
        print htmlentities("\xbc\xbd\xbe", ENT_QUOTES, '')."\n";
?>

I expect this result:

iso-8859-15
string(20) "&OElig;&oelig;&Yuml;"

My actual results are:

iso-8859-15
string(24) "&frac14;&frac12;&frac34;"

Why doesn't htmlentities("\xbc\xbd\xbe", ENT_QUOTES, '') use the value for default_charset as the third parameter?  

Thanks.

Jim

P.S. I also tried htmlentities("\xbc\xbd\xbe", ENT_QUOTES) and htmlentities("\xbc\xbd\xbe").  They produced the same results.  I tried htmlentities("\xbc\xbd\xbe", ENT_QUOTES, ini_get('default_charset')) and it works.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 18:01:34 2024 UTC