GNOME Bugzilla – Bug 611687
gconvert g_filename_to_uri doesn't do what the documentation says
Last modified: 2017-07-25 10:20:29 UTC
Hi, I stumbled across some strange behaviour when working with g_filename_to_uri on Windows. According to the documentation, http://library.gnome.org/devel/glib/stable/glib-Character-Set-Conversion.html#g-filename-to-uri filename : an absolute filename specified in the GLib file name encoding, which is the on-disk file name bytes on Unix, and UTF-8 on Windows Now, by looking at the code, I can see that the function doing this stuff is g_filename_to_uri_utf8. g_filename_to_uri first converts filename from the locale to utf8 and then calls g_filename_to_uri_utf8. If I call g_filename_to_uri with a utf8 encoded filename, this function returns a twice encoded string. If I have for instance a "ë" in UTF-16, it is transformed into 0xC3 AB ("Ã" + "«") in order to be UTF-8 compliant. If I try to input C:\\ë into g_filename_to_uri, I get as a result this: file:///C:/%C3%83%C2%AB which is basically wrong (it should be file:///C:/%C3%AB). Can someone explain me this strange behaviour? Is it something expected or am I doing things wrong? Thanks, Regards, Fernando
1) g_filename_to_uri is not used on Windows. There is/was some ifdeffery to replace it with g_filename_to_uri_utf8. It was used when glib used ANSI paths on Windows and up until bug 780634 it was exported for ABI compat. That locale code is now gone. 2) I can't reproduce the problem, I get "%C3%AB" using glib master. Maybe there was a problem and it was fixed in the mean time...