summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-07-11 09:21:15 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-07-11 09:22:01 -0400
commit1cb1767a29458b3d16d6b161b4ee34dd496ff60d (patch)
tree3ce23a17c56be6b6cbd4163b59247cd380a674e5
parentccb03ac39d5360433e62b8b82e474aa044421bd9 (diff)
util: fix has cc check and add test
-rw-r--r--src/shared/util.c2
-rw-r--r--src/test/test-util.c15
2 files changed, 16 insertions, 1 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 33427981eb..75dc58b63d 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -5419,7 +5419,7 @@ bool string_has_cc(const char *p, const char *ok) {
for (t = p; *t; t++) {
if (ok && strchr(ok, *t))
- return false;
+ continue;
if (*t > 0 && *t < ' ')
return true;
diff --git a/src/test/test-util.c b/src/test/test-util.c
index 44921bd156..ed91a67d10 100644
--- a/src/test/test-util.c
+++ b/src/test/test-util.c
@@ -731,6 +731,20 @@ static void test_filename_is_safe(void) {
assert_se(filename_is_safe("o.o"));
}
+static void test_string_has_cc(void) {
+ assert_se(string_has_cc("abc\1", NULL));
+ assert_se(string_has_cc("abc\x7f", NULL));
+ assert_se(string_has_cc("abc\x7f", NULL));
+ assert_se(string_has_cc("abc\t\x7f", "\t"));
+ assert_se(string_has_cc("abc\t\x7f", "\t"));
+ assert_se(string_has_cc("\x7f", "\t"));
+ assert_se(string_has_cc("\x7f", "\t\a"));
+
+ assert_se(!string_has_cc("abc\t\t", "\t"));
+ assert_se(!string_has_cc("abc\t\t\a", "\t\a"));
+ assert_se(!string_has_cc("a\ab\tc", "\t\a"));
+}
+
static void test_ascii_strlower(void) {
char a[] = "AabBcC Jk Ii Od LKJJJ kkd LK";
assert_se(streq(ascii_strlower(a), "aabbcc jk ii od lkjjj kkd lk"));
@@ -937,6 +951,7 @@ int main(int argc, char *argv[]) {
test_log2i();
test_foreach_string();
test_filename_is_safe();
+ test_string_has_cc();
test_ascii_strlower();
test_files_same();
test_is_valid_documentation_url();