diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2015-07-30 14:07:01 +0200 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2015-07-30 16:56:27 +0200 |
commit | e65854f609dbf2e8f696fb217a468282e68b5e28 (patch) | |
tree | 487791e8de2e8a312753d2565fccfc4732d72c6e | |
parent | d1b6835ada12408bd415939e49a2ce8f962220ed (diff) | |
download | NetworkManager-e65854f609dbf2e8f696fb217a468282e68b5e28.tar.gz |
libnm-core: strip nm_utils_enum_from_str() input string
-rw-r--r-- | libnm-core/nm-utils.c | 6 | ||||
-rw-r--r-- | libnm-core/tests/test-general.c | 2 |
2 files changed, 6 insertions, 2 deletions
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); |