After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 729563 - GOption: A short option's value is included in G_OPTION_REMAINING
GOption: A short option's value is included in G_OPTION_REMAINING
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
2.40.x
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2014-05-05 12:36 UTC by Kjell Ahlstedt
Modified: 2014-05-06 00:34 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Test case (2.69 KB, text/plain)
2014-05-05 12:36 UTC, Kjell Ahlstedt
  Details
patch: goption: Don't include parsed option values in G_OPTION_REMAINING (1006 bytes, patch)
2014-05-05 12:43 UTC, Kjell Ahlstedt
none Details | Review

Description Kjell Ahlstedt 2014-05-05 12:36:31 UTC
Created attachment 275886 [details]
Test case

After a call to g_option_context_set_ignore_unknown_options(context, TRUE),
the values of short options are included in the array returned by a
G_OPTION_REMAINING option. If G_OPTION_REMAINING is not used, the short
options' values are (correctly) removed from argv[].

Some results with the attached test case:

  $ ./testcase --number 4 --text=hello file1 file2
  ignore=0:0, remaining=0:0, number=4, text=hello, files=, argv= ./testcase file1 file2

  $ ./testcase -r --number 4 --text=hello file1 file2
  ignore=0:0, remaining=1:1, number=4, text=hello, files= file1 file2, argv= ./testcase

  $ ./testcase -n 4 -t hello file1 file2
  ignore=0:0, remaining=0:0, number=4, text=hello, files=, argv= ./testcase file1 file2

  $ ./testcase -r -n 4 -t hello file1 file2
  ignore=0:0, remaining=1:1, number=4, text=hello, files= file1 file2, argv= ./testcase

  $ ./testcase -i --number 4 --text=hello file1 file2
  ignore=1:1, remaining=0:0, number=4, text=hello, files=, argv= ./testcase file1 file2

  $ ./testcase -ri --number 4 --text=hello file1 file2
  ignore=1:1, remaining=1:1, number=4, text=hello, files= file1 file2, argv= ./testcase

  $ ./testcase -i -n 4 -t hello file1 file2
  ignore=1:1, remaining=0:0, number=4, text=hello, files=, argv= ./testcase file1 file2

  $ ./testcase -ri -n 4 -t hello file1 file2
  ignore=1:1, remaining=1:1, number=4, text=hello, files= 4 hello file1 file2, argv= ./testcase

The last result is wrong. "4" and "hello" shall not be considered remaining
options.

I will add a patch.
Comment 1 Kjell Ahlstedt 2014-05-05 12:43:51 UTC
Created attachment 275887 [details] [review]
patch: goption: Don't include parsed option values in G_OPTION_REMAINING
Comment 2 Matthias Clasen 2014-05-06 00:34:48 UTC
thanks, I've turned you testcase into a testcase in glib/tests/option-context.c