Bug #75574 [Fbk]: putenv does not work properly if the parameter contains Chinese character
| From: | ab@php.net | Date: | Sun, 26 Nov 2017 21:07:33 +0000 |
| Subject: | Bug #75574 [Fbk]: putenv does not work properly if the parameter contains Chinese character | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-212727@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
Updated by: ab@php.net
Reported by: ganlvtech at qq dot com
Summary: putenv does not work properly if the parameter
contains Chinese character
Status: Feedback
Type: Bug
Package: Scripting Engine problem
Operating System: Windows 10 (1709) zh-CN
PHP Version: 7.1.12
Block user comment: N
Private report: N
New Comment:
Ah, and the encoding of the file you've posted, too.
Thanks.
Previous Comments:
------------------------------------------------------------------------
[2017-11-26 21:04:14] ab@php.net
Thanks for the report. Could you also tell whether your build is TS/NTS and what is your INI for
default_charset and internal_encoding?
Thanks.
------------------------------------------------------------------------
[2017-11-26 19:14:50] ganlvtech at qq dot com
Description:
------------
If the value ends with odd numbers of Chinese characters, it returns false and getenv cannot get the
environment variable just set.
If the value ends with even numbers of Chinese characters, it works well and returns true.
If the value ends with a ASCII character, although there are some Chinese characters in the string,
it still works well.
If the Chinese characters is split by ASCII character, only the number of the last part of Chinese
characters affects the result.
Japanese character also cause this problem.
On ubuntu 16.04.3 with php 7.0.22 everything is OK. So the bug may be only for Windows.
I have checked the php-src/ext/standard/basic_functions.c PHP_FUNCTION(putenv), but I'm sorry
that I cannot find the solution.
This problem might be similar to the fixed bug #50690(putenv() does not assign values to env. vars
when the value is one character), but this one is for non-ASCII character.
Thank you.
Test script:
---------------
<?php
// Chinese character 'å' === urldecode('%E5%95%8A')
var_dump(putenv('FOO=å')); // false
// var_dump(putenv('FOO=' . urldecode('%E5%95%8A'))); // false
var_dump(putenv('FOO=åå')); // true
// var_dump(putenv('FOO=' . urldecode('%E5%95%8A%E5%95%8A'))); // true
var_dump(putenv('FOO=ååå')); // false
var_dump(putenv('FOO=åååå')); // true
// odd got false, even got true.
var_dump(putenv('FOO=åa')); // true
var_dump(putenv('FOO=åaå')); // false
var_dump(putenv('FOO=åaåa')); // true
var_dump(putenv('FOO=åaåaå')); // false
var_dump(putenv('FOO=åaåå')); // true
var_dump(putenv('FOO=åaååå')); // false
var_dump(putenv('FOO=åaåååå')); // true
// If the value ends with odd numbers of Chinese character, it returns false.
?>
Expected result:
----------------
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
bool(true)
Actual result:
--------------
bool(false)
bool(true)
bool(false)
bool(true)
bool(true)
bool(false)
bool(true)
bool(false)
bool(true)
bool(false)
bool(true)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75574&edit=1