From f9e890ae55d877d2eb22d16c323f2edf605d3e25 Mon Sep 17 00:00:00 2001 From: Mike Place Date: Thu, 6 Feb 2014 16:13:40 -0700 Subject: [PATCH 1/2] Nested dict recursion for subdict_match This code needs some careful review because it's used in a bunch of places and this is a potentially substantial change. What we're doing here is to recurse back through the function if we encounter a dict that's an element of a list. This solves match against something like {'baz': [{'foo': 'bar}]} but it could have unintended side-effects that I haven't yet encountered. It supports matching against the sub-list-dict (just made that term up) either directly like 'baz:foo:bar' or 'baz:*:foo:bar'. Comments welcome. Refs #9991. --- salt/utils/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/salt/utils/__init__.py b/salt/utils/__init__.py index c17e169388..d9da5d76e2 100644 --- a/salt/utils/__init__.py +++ b/salt/utils/__init__.py @@ -1099,6 +1099,11 @@ def subdict_match(data, expr, delim=':', regex_match=False): if isinstance(match, list): # We are matching a single component to a single list member for member in match: + if isinstance(member, dict): + if matchstr.startswith('*:'): + matchstr = matchstr.lstrip('*:') + if subdict_match(member, matchstr, regex_match=regex_match): + return True if _match(member, matchstr, regex_match=regex_match): return True continue From aa8909b89222f87315e82341b5276f37afbdd5eb Mon Sep 17 00:00:00 2001 From: Mike Place Date: Thu, 6 Feb 2014 16:46:15 -0700 Subject: [PATCH 2/2] Don't lstrip(). Thanks @terminalmage for the reminder. --- salt/utils/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/salt/utils/__init__.py b/salt/utils/__init__.py index d9da5d76e2..3cc413df46 100644 --- a/salt/utils/__init__.py +++ b/salt/utils/__init__.py @@ -1101,7 +1101,7 @@ def subdict_match(data, expr, delim=':', regex_match=False): for member in match: if isinstance(member, dict): if matchstr.startswith('*:'): - matchstr = matchstr.lstrip('*:') + matchstr = matchstr[2:] if subdict_match(member, matchstr, regex_match=regex_match): return True if _match(member, matchstr, regex_match=regex_match):