diff --git a/core/matcher.py b/core/matcher.py index 84a6efa12fc0c9c782afca4f6256b9e5a6cc217d..459e518a83163cd84db7389d0d14f8081e4d7e0f 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 d94e0b03a32e9213299d53e26d0fb4d46981ca33..6dcc28d1a41362c7a6e3f395183a1e4ead3a8936 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):