Bug #75574 [Csd]: putenv does not work properly if parameter contains non-ASCII unicode character
| From: | ganlvtech at qq dot com | Date: | Tue, 28 Nov 2017 06:06:00 +0000 |
| Subject: | Bug #75574 [Csd]: putenv does not work properly if parameter contains non-ASCII unicode character | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-212762@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75574&edit=1
ID: 75574
User updated by: ganlvtech at qq dot com
Reported by: ganlvtech at qq dot com
Summary: putenv does not work properly if parameter contains
non-ASCII unicode character
Status: Closed
Type: Bug
Package: Scripting Engine problem
Operating System: Windows 10 (1709) zh-CN
PHP Version: 7.1.12 nts Win32 VC14 x64
Block user comment: N
Private report: N
New Comment:
Tested the newest snapshot (7.1.13-dev nts).
Using test script from php-src/ext/standard/tests/general_functions/putenv_bug75574_utf8.phpt
Run 'php test.php', test passed.
Run 'php -S 127.0.0.1:8000', and visit http://127.0.0.1/test.php, test passed.
But when I run 'php-cgi -b 127.0.0.1:9000', and use nginx fastcgi_pass to php-cgi, putenv
is OK, but getenv will return cp936 2-byte char instead of utf8 3-byte char.
(In fact, I start php-cgi with 'RunHiddenConsole php-cgi -b 127.0.0.1:9000')
I would test some more to find if there's some error in my setting.
Previous Comments:
------------------------------------------------------------------------
[2017-11-27 17:53:15] ab@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=2b7d283cc5589077d7ecc23cc9b2827759cab5c2
Log: Fixed bug #75574 putenv does not work properly if parameter contains non-ASCII unicode
character
------------------------------------------------------------------------
[2017-11-27 10:18:06] ab@php.net
Thanks for more info. Yeah, i guess the issue is that we the A versions of the API are used. Getting
a VM with Chinese simplified to check more.
Thanks.
------------------------------------------------------------------------
[2017-11-27 04:15:19] ganlvtech at qq dot com
https://stackoverflow.com/questions/19008182/c11-and-win32-wchar-t
if php uses SetEnvironmentVariableA now, it can convert UTF8 to UTF16 and use
SetEnvironmentVariableW.
I don't know if this is a solution of this problem.
------------------------------------------------------------------------
[2017-11-27 04:15:18] ganlvtech at qq dot com
https://stackoverflow.com/questions/19008182/c11-and-win32-wchar-t
if php uses SetEnvironmentVariableA now, it can convert UTF8 to UTF16 and use
SetEnvironmentVariableW.
I don't know if this is a solution of this problem.
------------------------------------------------------------------------
[2017-11-27 03:56:00] ganlvtech at qq dot com
Oh, if I change the encoding of the test script from UTF-8 to GBK (from 3 bytes per char to 2 bytes
per char), it will be OK.
I don't know if there is any settings wrong with my Windows (Chinese simplyfied version). It
seems that the system only accept non-ASCII char in 2 bytes (in another word, system use GBK
encoding). System accept & return the value in GBK encoding, but php pass & retrieve env var
in UTF-8 encoding.
I set an Environment variable in control panel, and retrieve the value in php by getenv. I got an
GBK encoding byte string cannot read. Because php7 use UTF-8 as default ouput encoding. I tried
echo iconv('GBK', 'UTF-8', getenv('FOO'));
and got the expected value.
I think this bug may be the limitation of Windows platform, and may not be fixed unless Windows
change the its default encoding to Unicode.
Thanks.
Another test script:
---------------
// Greek_alphabet 'α' === urldecode('%CE%B1')
var_dump(putenv('FOO=α')); // true
php.ini:
---------------
; PHP's default character set is set to UTF-8.
; http://php.net/default-charset
default_charset = "UTF-8"
; PHP internal character encoding is set to empty.
; If empty, default_charset is used.
; http://php.net/internal-encoding
;internal_encoding =
PHP Version: php-7.1.12-nts-Win32-VC14-x64
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=75574
--
Edit this bug report at https://bugs.php.net/bug.php?id=75574&edit=1