From f4abd5528f7478a46e6c33e8afec12b4b2fd3a71 Mon Sep 17 00:00:00 2001 From: James Light Date: Tue, 16 Nov 2021 07:24:14 -0500 Subject: [PATCH] Fix security group filters 2 (#4481) --- moto/core/utils.py | 23 ++++--- moto/ec2/models.py | 42 +++++++------ tests/test_ec2/test_security_groups.py | 86 +++++++++++++++++++++++++- 3 files changed, 123 insertions(+), 28 deletions(-) diff --git a/moto/core/utils.py b/moto/core/utils.py index 519fabd35..d5bc7634f 100644 --- a/moto/core/utils.py +++ b/moto/core/utils.py @@ -399,13 +399,22 @@ def merge_dicts(dict1, dict2, remove_nulls=False): dict1.pop(key) -def glob_matches(pattern, string): - """AWS API-style globbing regexes""" - pattern, n = re.subn(r"[^\\]\*", r".*", pattern) - pattern, m = re.subn(r"[^\\]\?", r".?", pattern) +def aws_api_matches(pattern, string): + """ + AWS API can match a value based on a glob, or an exact match + """ + # use a negative lookback regex to match stars that are not prefixed with a backslash + # and replace all stars not prefixed w/ a backslash with '.*' to take this from "glob" to PCRE syntax + pattern, n = re.subn(r"(?