From 0817b50642b8dfbb9a0197ff8b637d3f1a2a29b9 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Tue, 21 Oct 2014 09:56:08 +0200 Subject: [PATCH] store: Let NULL values never match a regex. --- src/core/store_lookup.c | 3 ++- t/unit/core/store_lookup_test.c | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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 }, -- 2.30.2