From dc61bd6cdeb619bca43dac3b6ef1576fd1f4f4f5 Mon Sep 17 00:00:00 2001 From: Dmitry Luhtionov Date: Mon, 19 Aug 2019 09:39:29 +0300 Subject: [PATCH 1/5] Fix matcher parsing --- core/matcher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/matcher.py b/core/matcher.py index 84a6efa12f..974157d037 100644 --- a/core/matcher.py +++ b/core/matcher.py @@ -53,7 +53,7 @@ def match(ctx, expr): def match_regex(v, rx): - return bool(re.search(rx, v)) + return bool(re.search(rx, str(v))) def match_in(v, iter): -- GitLab From 1b1c7279c63a0793d9eb9790acb7a6ba188466a4 Mon Sep 17 00:00:00 2001 From: Dmitry Luhtionov Date: Mon, 19 Aug 2019 11:30:25 +0300 Subject: [PATCH 2/5] Fix --- core/matcher.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/matcher.py b/core/matcher.py index 974157d037..4854251067 100644 --- a/core/matcher.py +++ b/core/matcher.py @@ -53,7 +53,7 @@ def match(ctx, expr): def match_regex(v, rx): - return bool(re.search(rx, str(v))) + return bool(re.search(rx, v or "")) def match_in(v, iter): -- GitLab From a80b7adb8a751b5f0be42797fcab67eec0391a79 Mon Sep 17 00:00:00 2001 From: Dmitry Luhtionov Date: Tue, 20 Aug 2019 10:00:13 +0300 Subject: [PATCH 3/5] Add test --- tests/test_matcher.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/test_matcher.py b/tests/test_matcher.py index d94e0b03a3..f3bfd2597b 100644 --- a/tests/test_matcher.py +++ b/tests/test_matcher.py @@ -49,6 +49,12 @@ def test_eq_and(raw, config, expected): {"platform": {"$regex": "^S"}, "vendor": "Dell"}, False, ), + ( + {"vendor": "Eltex", "image": "_image.bin"}, + {"image": {"$regex": "^\S+"}, "vendor": "Eltex"}, + True, + ), + ({"vendor": "Eltex"}, {"image": {"$regex": "^\S+"}, "vendor": "Eltex"}, False), ], ) def test_regex(raw, config, expected): -- GitLab From f665e00e290e22df235b175b588cbb74b33e24e7 Mon Sep 17 00:00:00 2001 From: Dmitry Luhtionov Date: Tue, 20 Aug 2019 10:02:54 +0300 Subject: [PATCH 4/5] Fix formatting --- tests/test_matcher.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_matcher.py b/tests/test_matcher.py index f3bfd2597b..6dcc28d1a4 100644 --- a/tests/test_matcher.py +++ b/tests/test_matcher.py @@ -51,10 +51,10 @@ def test_eq_and(raw, config, expected): ), ( {"vendor": "Eltex", "image": "_image.bin"}, - {"image": {"$regex": "^\S+"}, "vendor": "Eltex"}, + {"image": {"$regex": r"^\S+"}, "vendor": "Eltex"}, True, ), - ({"vendor": "Eltex"}, {"image": {"$regex": "^\S+"}, "vendor": "Eltex"}, False), + ({"vendor": "Eltex"}, {"image": {"$regex": r"^\S+"}, "vendor": "Eltex"}, False), ], ) def test_regex(raw, config, expected): -- GitLab From 0c94ac3b988e671e5c532b66fd51e5dc4351e7a1 Mon Sep 17 00:00:00 2001 From: Dmitry Luhtionov Date: Tue, 20 Aug 2019 15:48:20 +0300 Subject: [PATCH 5/5] Fix --- core/matcher.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/matcher.py b/core/matcher.py index 4854251067..459e518a83 100644 --- a/core/matcher.py +++ b/core/matcher.py @@ -37,6 +37,8 @@ def match(ctx, expr): return False if isinstance(expr[x], dict): for m in expr[x]: + if ctx[x] is None: + continue mf = matchers.get(m) if mf and not isinstance(expr[x][m], tuple): if not mf(ctx[x], expr[x][m]): @@ -53,7 +55,7 @@ def match(ctx, expr): def match_regex(v, rx): - return bool(re.search(rx, v or "")) + return bool(re.search(rx, v)) def match_in(v, iter): -- GitLab