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
glib: Remove ending NUL when converting Variant to OsString. #625
glib: Remove ending NUL when converting Variant to OsString. #625
Conversation
Makes sense to me but now I'm wondering if maybe we should add Might make sense bringing that up as a GLib issue if this is not documented anywhere. |
I was just thinking about that!
I think it is documented if you look deep enough:
With
So my guess is that the NUL byte is mandatory. Should I update this pull-request or create a new one, as this is technically a different issue? What I don't quite understand here is why the Windows version stores I don't have a Windows machine around to try, maybe I'll try with Wine and let you know. |
That does look like it should probably always get converted to utf8, to match what glib always does. Exposing the utf16 is a rust thing |
The "local options" in
That was because
I think your analysis is correct in that regard and it should indeed be assuming / putting a |
Hmm, yes it does look like the "local encoding" on windows is supposed to be utf8: g_win32_get_command_line |
Ok, I'm trying to fix everything in one go. I've just added a new commit and squashed the PR. I've added changes to I'm not totally sure about the lossy conversions in Windows... But then, if you have a Windows file name that is not UTF-8 valid, I think that you have already lost: Rust can handle that with the internal WTF-8 encoding of OsString, but AFAIK glib uses pure UTF-8. The alternative to lossy conversion would be to replace them with an empty string, as Variant does with the missing NUL. I have tested my example from the original bug report, both in Linux and in Windows (tricky!) and now it seems to work great. (previously Windows failed with something about the type of variant being "aq" instead of "ay"). |
I would go with how it's implemented in |
Otherwise this looks all good to me! |
I have force-pushed a new version of this PR. Funnily, using |
The implementation looks all good to me, just needs a little bit of cleanup and then this can go in.
That's nice :) |
I've just force-pushed a new version. |
Variants that hold filenames (and probably other OsString) like values are actually stored as NUL-teminated byte arrays, not strings, using the filesystem encoding. Use the same helper function from translate.rs to do the conversion.
Fixes #620.