Code

store: Let NULL values never match a regex.
authorSebastian Harl <sh@tokkee.org>
Tue, 21 Oct 2014 07:56:08 +0000 (09:56 +0200)
committerSebastian Harl <sh@tokkee.org>
Tue, 21 Oct 2014 07:56:08 +0000 (09:56 +0200)
src/core/store_lookup.c
t/unit/core/store_lookup_test.c

index f1baea644a4c2f2b2ee16e18ecc3d531f0e4f723..5187a3785b3b737be5964906c11c32e0d60c384d 100644 (file)
@@ -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];
index c5aad2c51f3670cd6f469d7650de349d6504a56a..0b81ebd0bab70dd35f7bb4a172c5a953c4ab73c9 100644 (file)
@@ -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 },