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
When specifying a envvar for a clikt option in Kotlin/Native, specifically mingwx64, if the specified envvar contains non-ascii characters, those characters will be turned into garbage, ie. the string öööÖÖÖäääÄÄÄåååÅÅÅ gets turned into ������������������.
I am however unsure if this is 100% reproducible on every Windows install, as the behavior of the getenv implementation, which I assume just delegates to the GetEnvironmentVariable function, which in turn either delegates to the GetEnvironmentVariableA or GetEnvironmentVariableW depending on a compiler flag when the Windows system was compiled, which in my case has been set to default to the ASCII implementation.
The way to solve this would be to provide an explicit implementation for the mingwx64 branch, instead of relying on the getenv posix function, the aforementioned GetEnvironmentVariableW function should instead be used, as that will always return a UTF-16 string.
I have myself implemented a function to do this in my own project, which can be seen here, which should work fine as far as I've tested it. It's licensed under Apache 2.0, so feel free to use it as long as you follow those guidelines.
Note that I have not tested whether the same behavior happens on Linux / MacOS, but from my knowledge it shouldn't happen, as those systems should be using UTF-8 by default.
The text was updated successfully, but these errors were encountered:
When specifying a
envvar
for a clikt option in Kotlin/Native, specifically mingwx64, if the specifiedenvvar
contains non-ascii characters, those characters will be turned into garbage, ie. the stringöööÖÖÖäääÄÄÄåååÅÅÅ
gets turned into������������������
.I have setup an example project to display this problem: clikt-windows-envvar
I am however unsure if this is 100% reproducible on every Windows install, as the behavior of the
getenv
implementation, which I assume just delegates to the GetEnvironmentVariable function, which in turn either delegates to the GetEnvironmentVariableA or GetEnvironmentVariableW depending on a compiler flag when the Windows system was compiled, which in my case has been set to default to the ASCII implementation.The way to solve this would be to provide an explicit implementation for the mingwx64 branch, instead of relying on the
getenv
posix function, the aforementionedGetEnvironmentVariableW
function should instead be used, as that will always return a UTF-16 string.I have myself implemented a function to do this in my own project, which can be seen here, which should work fine as far as I've tested it. It's licensed under Apache 2.0, so feel free to use it as long as you follow those guidelines.
Note that I have not tested whether the same behavior happens on Linux / MacOS, but from my knowledge it shouldn't happen, as those systems should be using UTF-8 by default.
The text was updated successfully, but these errors were encountered: