From 92d19f76449817dfb125da9510d478a30eed37bc Mon Sep 17 00:00:00 2001 From: Sumit Bose Date: Mon, 25 Aug 2014 10:36:46 +0200 Subject: Replace space: add some checks This patch adds some additional checks if the option for replacing spaces in user and group names is used. When replacing space with the replacement character it is checked if the name already contains the replacement character. If it does the unmodified name is returned because in this case a revers operation would not be possible. For the reverse operation is it checked if the input contains both a space and the replacement character. If this is true the unmodified name is returned as well, because we have to assume that it is the original name because otherwise it wouldn't contain both characters. Additionally a shortcut if the replacement characters is a space and tests for the new checks are added. The man page is updated accordingly. Related to https://fedorahosted.org/sssd/ticket/1854 and https://fedorahosted.org/sssd/ticket/2397 . Reviewed-by: Jakub Hrozek --- src/tests/cmocka/test_string_utils.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/tests/cmocka') diff --git a/src/tests/cmocka/test_string_utils.c b/src/tests/cmocka/test_string_utils.c index 93d7d716f..e446387d6 100644 --- a/src/tests/cmocka/test_string_utils.c +++ b/src/tests/cmocka/test_string_utils.c @@ -47,6 +47,7 @@ void test_replace_whitespaces(void **state) { " ", " ", ' ' }, { "abcd", "abcd", ' ' }, { "a b c d", "a b c d", ' ' }, + { "a b^c d", "a b^c d", '^' }, { NULL, NULL, '\0' }, }; @@ -92,6 +93,8 @@ void test_reverse_replace_whitespaces(void **state) { "abcd", "abcd", '-' }, { "a-b-c-d", "a b c d", '-' }, { "-a-b-c-d-", " a b c d ", '-' }, + { "a b c d", "a b c d", '-' }, + { " a b c d ", " a b c d ", '-' }, { "^", " ", '^' }, { "^^^^", " ", '^' }, { "abcd", "abcd", '^' }, @@ -102,6 +105,7 @@ void test_reverse_replace_whitespaces(void **state) { "abcd", "abcd", ' ' }, { "a b c d", "a b c d", ' ' }, { " a b c d ", " a b c d ", ' ' }, + { "a b^c d", "a b^c d", '^' }, { NULL, NULL, '\0' }, }; -- cgit