You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Env vars with non-ASCII values are mangled when read from $_SERVER on Windows #7896
When run with variables_order = "EGPCS" and FOO=GüИter传 set in the environment variables in Windows (or using $env:FOO = 'GüИter传' in PowerShell before executing the test file above).
Doing the same in WSL/Ubuntu seems to yield the correct result, so I assume it's Windows specific.
Regarding PHP version, it appears all versions <7.2 fail completely, with even getenv() returning string(7) "G?ter?" or string(7) "Gⁿ?ter?" for 5.x. From PHP 7.2 onwards I get the behavior described above.
Nope, no better idea per se, but note that this wouldn't help with env var names containing non-ASCII characters (e.g. FÖÖ=bar). If that's important, you could traverse getenv() instead (that's likely a bit faster anyway).
@cmb69 it's been brought to my attention that calling getenv() also still suffers from the same issue and mangles unicode values. Only getenv('FOO') appears to work correctly.
Activity
cmb69 commentedon Jan 6, 2022
This is likely due to fixing https://bugs.php.net/75574, so should be fixed as of PHP 7.1.13 and 7.2.1, respectively. That fix only affected
getenv(), though, but not_php_import_environment_variables(and possibly other places).Seldaek commentedon Jan 6, 2022
Thanks, do you see any way to mitigate/detect this in userland?
I see that doing this when starting up to ensure
$_SERVERis in a good state appears to work.. not sure if there's a better way:Once fixed in a release I'll at least be able to exclude this hackery from newer PHP versions.
cmb69 commentedon Jan 6, 2022
Nope, no better idea per se, but note that this wouldn't help with env var names containing non-ASCII characters (e.g.
FÖÖ=bar). If that's important, you could traversegetenv()instead (that's likely a bit faster anyway).Seldaek commentedon Jan 6, 2022
Ok yes using
getenv()once makes more sense, although we're really only interested in ascii vars in the context of Composer.Workaround PHP bug with env vars not being read correctly on Windows, f…
Seldaek commentedon Jan 7, 2022
@cmb69 it's been brought to my attention that calling
getenv()also still suffers from the same issue and mangles unicode values. Onlygetenv('FOO')appears to work correctly.So here's a working workaround: https://github.com/composer/composer/blob/d9619985dbabb58255fb27cf78fe702345d31793/bin/composer#L68-L76
cmb69 commentedon Jan 7, 2022
Argh!
getenv()without parameter also callsphp_import_environment_variables(), and I tested with an already patched version.Fix phpGH-7896: Environment vars may be mangled on Windows
Fix GH-7896: Environment vars may be mangled on Windows
Merge branch 'PHP-8.0' into PHP-8.1
Merge branch 'PHP-8.1'
Seldaek commentedon Jan 21, 2022
Thanks @cmb69 !