From: Sebastian Harl Date: Tue, 21 Oct 2014 07:56:08 +0000 (+0200) Subject: store: Let NULL values never match a regex. X-Git-Tag: sysdb-0.6.0~82 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=0817b50642b8dfbb9a0197ff8b637d3f1a2a29b9;p=sysdb.git store: Let NULL values never match a regex. --- diff --git a/src/core/store_lookup.c b/src/core/store_lookup.c index f1baea6..5187a37 100644 --- a/src/core/store_lookup.c +++ b/src/core/store_lookup.c @@ -530,7 +530,8 @@ match_regex(sdb_store_matcher_t *m, sdb_store_obj_t *obj, free(raw); } - if (sdb_store_expr_eval(CMP_M(m)->left, obj, &v, filter)) + if ((sdb_store_expr_eval(CMP_M(m)->left, obj, &v, filter)) + || (sdb_data_isnull(&v))) status = 0; else { char value[sdb_data_strlen(&v) + 1]; diff --git a/t/unit/core/store_lookup_test.c b/t/unit/core/store_lookup_test.c index c5aad2c..0b81ebd 100644 --- a/t/unit/core/store_lookup_test.c +++ b/t/unit/core/store_lookup_test.c @@ -797,6 +797,11 @@ START_TEST(test_scan) "NOT attribute['x'] = ''", 2 }, /* filter always matches */ { "attribute = 'x'", NULL, 0 }, { "attribute['k1'] = 'v1'", NULL, 1 }, + { "attribute['k1'] =~ 'v'", NULL, 2 }, + { "attribute['k1'] !~ 'v'", NULL, 1 }, + { "attribute['x1'] =~ 'v'", NULL, 0 }, + { "attribute['x1'] =~ 'NULL'", NULL, 0 }, + { "attribute['x1'] !~ 'v'", NULL, 3 }, { "attribute['k1'] IS NULL", NULL, 1 }, { "attribute['x1'] IS NULL", NULL, 3 }, { "attribute['k1'] IS NOT NULL", NULL, 2 },