GNOME Bugzilla – Bug 737137
g_option_context_parse() with an UTF-8 G_OPTION_ARG_FILENAME fails
Last modified: 2014-09-22 20:24:40 UTC
Created attachment 286837 [details] Test case showing the bug The attached program shows that g_option_context_parse() fails when a GOptionEntry of type G_OPTION_ARG_STRING is provided with an UTF-8 string including characters not in ASCII, giving the error "Invalid byte sequence in conversion input (g_convert_error, 1)". I can workaround this issue by specifying the type of the GOptionEntry to G_OPTION_ARG_STRING, but I would prefer it to be properly set as string. Gentoo Linux up to date, glib-2.40.0. Try the test case with: # This is just an example, it fails with any UTF-8 string # with characters not in ASCII $ ./test -o 'ñ' ** (test:21267): WARNING **: file test.c: line 32: unexpected error: Invalid byte sequence in conversion input (g_convert_error, 1) Argument 1: ./test Argument 2: -o Argument 3: ñ
Sorry, the second paragraph is: "I can workaround this issue by specifying the type of the GOptionEntry to G_OPTION_ARG_FILENAME, but I would prefer it to be properly set as string." Sorry for the confusion.
[desrt@humber ~]$ ./test ĝuste? Argument 1: ./test Argument 2: ĝuste? Seems to work for me. Is your locale set to utf-8 properly? We try to convert from your locale to utf-8, so maybe that's the issue. What is the output of 'locale'?
(In reply to comment #2) > [desrt@humber ~]$ ./test ĝuste? > Argument 1: ./test > Argument 2: ĝuste? > > > Seems to work for me. Yeah, *that* works here too. Try this please: [desrt@humber ~]$ ./test -o ĝuste? > Is your locale set to utf-8 properly? We try to convert from your locale to > utf-8, so maybe that's the issue. I believe my locale es setup properly. > What is the output of 'locale'? $ locale LANG=en_US.UTF-8 LC_CTYPE="en_US.UTF-8" LC_NUMERIC=en_US.utf8 LC_TIME=en_US.utf8 LC_COLLATE="en_US.UTF-8" LC_MONETARY=en_US.utf8 LC_MESSAGES="en_US.UTF-8" LC_PAPER=en_US.utf8 LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT=es_MX.utf8 LC_IDENTIFICATION="en_US.UTF-8" LC_ALL=
Sorry -- my bad. I was able to reproduce. The problem is that you really are in a C locale, at least in this program. You need to call setlocale(LC_ALL, ""); at the start of main in order to initialise the locale system. Once I make that change, everything works fine.
Thank you.