Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option with envvar containing non-ascii characters will return garbage on Windows #362

Closed
Olivki opened this issue Jun 26, 2022 · 1 comment · Fixed by #364
Closed

Option with envvar containing non-ascii characters will return garbage on Windows #362

Olivki opened this issue Jun 26, 2022 · 1 comment · Fixed by #364

Comments

@Olivki
Copy link

Olivki commented Jun 26, 2022

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 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 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.

@JesperVa
Copy link

This has recently been affecting me in one of my private projects as well.

I hope it's resolved soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants