Bug #75574 [NEW]: putenv does not work properly if the parameter contains Chinese character
| From: | ganlvtech at qq dot com | Date: | Sun, 26 Nov 2017 19:14:52 +0000 |
| Subject: | Bug #75574 [NEW]: putenv does not work properly if the parameter contains Chinese character | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-212725@lists.php.net to get a copy of this message | ||
From: ganlvtech at qq dot com
Operating system: Windows 10 (1709) zh-CN
PHP version: 7.1.12
Package: Scripting Engine problem
Bug Type: Bug
Bug description:putenv does not work properly if the parameter contains Chinese character
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 bug report at https://bugs.php.net/bug.php?id=75574&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75574&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75574&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75574&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=75574&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=75574&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=75574&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=75574&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=75574&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=75574&r=support
Expected behavior: https://bugs.php.net/fix.php?id=75574&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=75574&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=75574&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=75574&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75574&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=75574&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=75574&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=75574&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75574&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=75574&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=75574&r=mysqlcfg