diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index 2cc6ed3955..ac30304596 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -4017,14 +4017,16 @@ gboolean nm_utils_enum_from_str (GType type, const char *str, GTypeClass *class; gboolean ret = FALSE; int value = 0; + gs_free char *stripped = NULL; g_return_val_if_fail (str, FALSE); + stripped = g_strstrip (strdup (str)); class = g_type_class_ref (type); if (G_IS_ENUM_CLASS (class)) { GEnumValue *enum_value; - enum_value = g_enum_get_value_by_nick (G_ENUM_CLASS (class), str); + enum_value = g_enum_get_value_by_nick (G_ENUM_CLASS (class), stripped); if (enum_value) { value = enum_value->value; ret = TRUE; @@ -4034,7 +4036,7 @@ gboolean nm_utils_enum_from_str (GType type, const char *str, gs_strfreev char **strv = NULL; int i; - strv = g_strsplit (str, ",", 0); + strv = g_strsplit (stripped, ",", 0); for (i = 0; strv[i]; i++) { if (!strv[i][0]) continue; diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c index dfe591298e..a033b9cbc2 100644 --- a/libnm-core/tests/test-general.c +++ b/libnm-core/tests/test-general.c @@ -4688,12 +4688,14 @@ static void test_nm_utils_enum (void) NM_TEST_GENERAL_COLOR_FLAGS_GREEN, "red,green"); test_nm_utils_enum_from_str_do (bool_enum, "", FALSE, 0, NULL); + test_nm_utils_enum_from_str_do (bool_enum, " ", FALSE, 0, NULL); test_nm_utils_enum_from_str_do (bool_enum, "invalid", FALSE, 0, NULL); test_nm_utils_enum_from_str_do (bool_enum, "yes", TRUE, NM_TEST_GENERAL_BOOL_ENUM_YES, NULL); test_nm_utils_enum_from_str_do (bool_enum, "no", TRUE, NM_TEST_GENERAL_BOOL_ENUM_NO, NULL); test_nm_utils_enum_from_str_do (bool_enum, "yes,no", FALSE, 0, NULL); test_nm_utils_enum_from_str_do (meta_flags, "", TRUE, 0, NULL); + test_nm_utils_enum_from_str_do (meta_flags, " ", TRUE, 0, NULL); test_nm_utils_enum_from_str_do (meta_flags, "foo", TRUE, NM_TEST_GENERAL_META_FLAGS_FOO, NULL); test_nm_utils_enum_from_str_do (meta_flags, "foo,baz", TRUE, NM_TEST_GENERAL_META_FLAGS_FOO | NM_TEST_GENERAL_META_FLAGS_BAZ, NULL);