Code

store: Let NREGEX (!~) not match on NULL values.
authorSebastian Harl <sh@tokkee.org>
Sun, 9 Nov 2014 12:47:36 +0000 (13:47 +0100)
committerSebastian Harl <sh@tokkee.org>
Sun, 9 Nov 2014 12:47:36 +0000 (13:47 +0100)
src/core/store_lookup.c
t/unit/core/store_lookup_test.c

index e2ec1b14936b3c6586bdd698bdd0c792519c61aa..eab37b4787bb2ba7e752ab6c06eb4b8bc019a7ea 100644 (file)
@@ -322,7 +322,7 @@ match_regex(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
 
        if ((sdb_store_expr_eval(CMP_M(m)->left, obj, &v, filter))
                        || (sdb_data_isnull(&v)))
-               status = 0;
+               status = INT_MAX;
        else {
                char value[sdb_data_strlen(&v) + 1];
                if (sdb_data_format(&v, value, sizeof(value), SDB_UNQUOTED) < 0)
@@ -334,6 +334,8 @@ match_regex(sdb_store_matcher_t *m, sdb_store_obj_t *obj,
        if (free_regex)
                regfree(&regex);
        sdb_data_free_datum(&v);
+       if (status == INT_MAX)
+               return 0;
        if (m->type == MATCHER_NREGEX)
                return !status;
        return status;
index 4d968a630f00a272b30c6edbfab4f6ad47a97517..18d811f0201edac5fd3a3ebc75d4f5951b981c65 100644 (file)
@@ -576,12 +576,12 @@ START_TEST(test_scan)
                { "attribute['k1'] =~ '^v1$'", NULL,   1 },
                { "attribute['k1'] =~ 'v'", NULL,      2 },
                { "attribute['k1'] =~ '1'", NULL,      1 },
-               { "attribute['k1'] !~ 'v'", NULL,      1 },
+               { "attribute['k1'] !~ 'v'", NULL,      0 },
                { "attribute['k1'] = 'v2'", NULL,      1 },
                { "attribute['k1'] =~ 'v2'", NULL,     1 },
                { "attribute['x1'] =~ 'v'", NULL,      0 },
                { "attribute['x1'] =~ 'NULL'", NULL,   0 },
-               { "attribute['x1'] !~ 'v'", NULL,      3 },
+               { "attribute['x1'] !~ 'v'", NULL,      0 },
                { "attribute['k1'] IS NULL", NULL,     1 },
                { "attribute['x1'] IS NULL", NULL,     3 },
                { "attribute['k1'] IS NOT NULL", NULL, 2 },
@@ -595,7 +595,7 @@ START_TEST(test_scan)
                { "attribute['k1'] != 'v1'", NULL,     1 },
                { "attribute['k1'] != 'v2'", NULL,     1 },
                { "ANY attribute != 'x' "
-                 "AND attribute['y'] !~ 'x'", NULL,   2 },
+                 "AND attribute['k1'] !~ 'x'", NULL,  2 },
        };
 
        sdb_strbuf_t *errbuf = sdb_strbuf_create(64);