mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-05-30 17:30:07 +02:00
Merge branch 'triple_dash' into 'master'
goption: Reject group options specified with three dashes Closes #1418 See merge request GNOME/glib!108
This commit is contained in:
commit
7830b65c5f
@ -2028,7 +2028,7 @@ g_option_context_parse (GOptionContext *context,
|
|||||||
|
|
||||||
/* Now look for --<group>-<option> */
|
/* Now look for --<group>-<option> */
|
||||||
dash = strchr (arg, '-');
|
dash = strchr (arg, '-');
|
||||||
if (dash)
|
if (dash && arg < dash)
|
||||||
{
|
{
|
||||||
/* Try the groups */
|
/* Try the groups */
|
||||||
list = context->groups;
|
list = context->groups;
|
||||||
|
@ -1822,6 +1822,49 @@ lonely_dash_test (void)
|
|||||||
g_option_context_free (context);
|
g_option_context_free (context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* test that three dashes are treated as non-options */
|
||||||
|
static void
|
||||||
|
triple_dash_test (void)
|
||||||
|
{
|
||||||
|
GOptionContext *context;
|
||||||
|
GOptionGroup *group;
|
||||||
|
gboolean retval;
|
||||||
|
GError *error = NULL;
|
||||||
|
gchar **argv;
|
||||||
|
gchar **argv_copy;
|
||||||
|
int argc;
|
||||||
|
gint arg1, arg2;
|
||||||
|
GOptionEntry entries [] =
|
||||||
|
{ { "foo", 0, 0, G_OPTION_ARG_INT, &arg1, NULL, NULL},
|
||||||
|
{ NULL }
|
||||||
|
};
|
||||||
|
GOptionEntry group_entries [] =
|
||||||
|
{ { "test", 0, 0, G_OPTION_ARG_INT, &arg2, NULL, NULL},
|
||||||
|
{ NULL }
|
||||||
|
};
|
||||||
|
|
||||||
|
context = g_option_context_new (NULL);
|
||||||
|
g_option_context_add_main_entries (context, entries, NULL);
|
||||||
|
|
||||||
|
group = g_option_group_new ("group", "Group description", "Group help", NULL, NULL);
|
||||||
|
g_option_group_add_entries (group, group_entries);
|
||||||
|
|
||||||
|
g_option_context_add_group (context, group);
|
||||||
|
|
||||||
|
/* Now try parsing */
|
||||||
|
argv = split_string ("program ---test 42", &argc);
|
||||||
|
argv_copy = copy_stringv (argv, argc);
|
||||||
|
|
||||||
|
retval = g_option_context_parse (context, &argc, &argv, &error);
|
||||||
|
g_assert_error (error, G_OPTION_ERROR, G_OPTION_ERROR_UNKNOWN_OPTION);
|
||||||
|
g_assert (retval == FALSE);
|
||||||
|
|
||||||
|
g_option_context_free (context);
|
||||||
|
g_clear_error (&error);
|
||||||
|
g_strfreev (argv_copy);
|
||||||
|
g_free (argv);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
missing_arg_test (void)
|
missing_arg_test (void)
|
||||||
{
|
{
|
||||||
@ -2619,6 +2662,7 @@ main (int argc,
|
|||||||
/* regression tests for individual bugs */
|
/* regression tests for individual bugs */
|
||||||
g_test_add_func ("/option/bug/unknown-short", unknown_short_test);
|
g_test_add_func ("/option/bug/unknown-short", unknown_short_test);
|
||||||
g_test_add_func ("/option/bug/lonely-dash", lonely_dash_test);
|
g_test_add_func ("/option/bug/lonely-dash", lonely_dash_test);
|
||||||
|
g_test_add_func ("/option/bug/triple-dash", triple_dash_test);
|
||||||
g_test_add_func ("/option/bug/missing-arg", missing_arg_test);
|
g_test_add_func ("/option/bug/missing-arg", missing_arg_test);
|
||||||
g_test_add_func ("/option/bug/dash-arg", dash_arg_test);
|
g_test_add_func ("/option/bug/dash-arg", dash_arg_test);
|
||||||
g_test_add_func ("/option/bug/short-remaining", short_remaining);
|
g_test_add_func ("/option/bug/short-remaining", short_remaining);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user