# Buggy code
def _dict_match(target, pattern, regex_match=False, exact_match=False):
    wildcard = pattern.startswith("*:")
    if wildcard:
        pattern = pattern[2:]

    if pattern == "*":
        # We are just checking that the key exists
        return True
    elif pattern in target:
        # We might want to search for a key
        return True
    elif subdict_match(
        target, pattern, regex_match=regex_match, exact_match=exact_match
    ):
        return True
    if wildcard:
        for key in target:
            if _match(key, pattern, regex_match=regex_match, exact_match=exact_match):
                return True
            if isinstance(target[key], dict):
                if _dict_match(
                    target[key],
                    pattern,
                    regex_match=regex_match,
                    exact_match=exact_match,
                ):
                    return True
            elif isinstance(target[key], list):
                for item in target[key]:
                    if _match(
                        item, pattern, regex_match=regex_match, exact_match=exact_match
                    ):
                        return True
    return False


# Traceback (UnicodeDecodeError)
2018-09-12 14:09:01,744 [salt.utils.minions                                    :696 ][ERROR   ][5648] Failed matching available minions with compound pattern: G@ip_interfaces:*:10.0.1.*
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/salt/utils/minions.py", line 683, in check_minions
_res = check_func(expr, delimiter, greedy)
File "/usr/lib/python2.7/site-packages/salt/utils/minions.py", line 578, in _check_compound_minions
_results = engine(*engine_args)
File "/usr/lib/python2.7/site-packages/salt/utils/minions.py", line 325, in _check_grain_minions
return self._check_cache_minions(expr, delimiter, greedy, 'grains')
File "/usr/lib/python2.7/site-packages/salt/utils/minions.py", line 315, in _check_cache_minions
exact_match=exact_match):
File "/usr/lib/python2.7/site-packages/salt/utils/data.py", line 579, in subdict_match
exact_match=exact_match):
File "/usr/lib/python2.7/site-packages/salt/utils/data.py", line 549, in _dict_match
exact_match=exact_match):
File "/usr/lib/python2.7/site-packages/salt/utils/data.py", line 526, in _match
return fnmatch.fnmatch(six.text_type(target).lower(), pattern.lower())
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 6: ordinal not in range(128)

# Fixed code
def _dict_match(target, pattern, regex_match=False, exact_match=False):
    wildcard = pattern.startswith("*:")
    if wildcard:
        pattern = pattern[2:]

    if pattern == "*":
        # We are just checking that the key exists
        return True
    elif pattern in target:
        # We might want to search for a key
        return True
    elif subdict_match(
        target, pattern, regex_match=regex_match, exact_match=exact_match
    ):
        return True
    if wildcard:
        for key in target:
            if isinstance(target[key], dict):
                if _dict_match(
                    target[key],
                    pattern,
                    regex_match=regex_match,
                    exact_match=exact_match,
                ):
                    return True
            elif isinstance(target[key], list):
                for item in target[key]:
                    if _match(
                        item, pattern, regex_match=regex_match, exact_match=exact_match
                    ):
                        return True
            elif _match(
                target[key], pattern, regex_match=regex_match, exact_match=exact_match
            ):
                return True
    return False