From 12987ed4ad2aea9835f786710fc0b2a7d554e83b Mon Sep 17 00:00:00 2001 From: Andrey Vertiprahov Date: Sun, 1 Sep 2019 08:11:31 +0000 Subject: [PATCH] Merge branch 'fix_matcher' into 'master' Fix matcher parsing See merge request noc/noc!2501 (cherry picked from commit 04ccf99b13dc86201196a6498e84c9d21d5d20e1) dc61bd6c Fix matcher parsing 1b1c7279 Fix a80b7adb Add test f665e00e Fix formatting 0c94ac3b Fix --- core/matcher.py | 2 ++ tests/test_matcher.py | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/core/matcher.py b/core/matcher.py index 84a6efa12f..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]): diff --git a/tests/test_matcher.py b/tests/test_matcher.py index d94e0b03a3..6dcc28d1a4 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": r"^\S+"}, "vendor": "Eltex"}, + True, + ), + ({"vendor": "Eltex"}, {"image": {"$regex": r"^\S+"}, "vendor": "Eltex"}, False), ], ) def test_regex(raw, config, expected): -- GitLab