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 11:03:01 +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-212768@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:
Using php.exe got expected result, but using php-cgi.exe putenv did not sets vars with Unicode.
Test script:
---------------
<?php
var_dump(putenv('FOO=å'));
var_dump(
echo %FOO%); // There will be a "\n" in the result.
var_dump(getenv('FOO'));
?>
Expected result:
----------------
bool(true)
string(4) "å
"
string(3) "å"
Actual result:
--------------
bool(true)
string(3) "С
"
string(2) "С"
The length of string is not equal to each other. putenv put vars using cp936 instead of Unicode.
You can use another test script to view the difference.
Test script:
--------------
<?php
var_dump(putenv('FOO=å'));
echo urlencode(echo %FOO%), PHP_EOL;
echo urlencode(getenv('FOO')), PHP_EOL;
?>
Expected result:
----------------
bool(true)
%E5%95%8A%0A
%E5%95%8A
Actual result:
--------------
bool(true)
%B0%A1%0A
%B0%A1
php snapshot: php-7.1-nts-windows-vc14-x64-r06202f0
Previous Comments:
------------------------------------------------------------------------
[2017-11-28 06:05:54] ganlvtech at qq dot com
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.
------------------------------------------------------------------------
[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.
------------------------------------------------------------------------
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