diff --git a/rollbar/lib/__init__.py b/rollbar/lib/__init__.py index 580d7287..58bf7557 100644 --- a/rollbar/lib/__init__.py +++ b/rollbar/lib/__init__.py @@ -56,18 +56,16 @@ def key_depth(key, canonicals) -> int: def key_match(key, canonical): - i = 0 + if len(key) < len(canonical): + return False + for k, c in zip(key, canonical): - i += 1 if '*' == c: continue if c == k: continue return False - if i < len(canonical) - 1: - return False - return True diff --git a/rollbar/test/test_lib.py b/rollbar/test/test_lib.py index a7f04b5d..fbaeaed0 100644 --- a/rollbar/test/test_lib.py +++ b/rollbar/test/test_lib.py @@ -30,6 +30,12 @@ def test_key_match_wildcard_end(self): self.assertTrue(key_match(key, canonical)) + def test_key_match_too_short(self): + canonical = ['body', 'trace', 'frames', '*', 'locals', '*'] + key = ['body', 'trace', 'frames', 5, 'locals'] + + self.assertFalse(key_match(key, canonical)) + def test_key_depth(self): canonicals = [['body', 'trace', 'frames', '*', 'locals', '*']] key = ['body', 'trace', 'frames', 5, 'locals', 'foo']