diff --git a/sentry_sdk/integrations/django/transactions.py b/sentry_sdk/integrations/django/transactions.py index f20866ef95..146a71a362 100644 --- a/sentry_sdk/integrations/django/transactions.py +++ b/sentry_sdk/integrations/django/transactions.py @@ -37,7 +37,7 @@ def get_regex(resolver_or_pattern): class RavenResolver(object): _optional_group_matcher = re.compile(r"\(\?\:([^\)]+)\)") - _named_group_matcher = re.compile(r"\(\?P<(\w+)>[^\)]+\)") + _named_group_matcher = re.compile(r"\(\?P<(\w+)>[^\)]+\)+") _non_named_group_matcher = re.compile(r"\([^\)]+\)") # [foo|bar|baz] _either_option_matcher = re.compile(r"\[([^\]]+)\|([^\]]+)\]") diff --git a/tests/integrations/django/test_transactions.py b/tests/integrations/django/test_transactions.py index 5cf3f17c32..799eaa4e89 100644 --- a/tests/integrations/django/test_transactions.py +++ b/tests/integrations/django/test_transactions.py @@ -19,6 +19,7 @@ example_url_conf = ( url(r"^api/(?P[\w_-]+)/store/$", lambda x: ""), + url(r"^api/(?P(v1|v2))/author/$", lambda x: ""), url(r"^report/", lambda x: ""), url(r"^example/", include(included_url_conf)), ) @@ -36,6 +37,14 @@ def test_legacy_resolver_complex_match(): assert result == "/api/{project_id}/store/" +def test_legacy_resolver_complex_either_match(): + resolver = RavenResolver() + result = resolver.resolve("/api/v1/author/", example_url_conf) + assert result == "/api/{version}/author/" + result = resolver.resolve("/api/v2/author/", example_url_conf) + assert result == "/api/{version}/author/" + + def test_legacy_resolver_included_match(): resolver = RavenResolver() result = resolver.resolve("/example/foo/bar/baz", example_url_conf)