From aa5b853bfa43bb3c44caa2ca42a7cff1d6e914eb Mon Sep 17 00:00:00 2001 From: Marcelo Galigniana Date: Sun, 4 Dec 2022 21:56:28 -0300 Subject: [PATCH] fix(integrations): support complex regex coming from DjangoCMS Fixes GH-1527 --- sentry_sdk/integrations/django/transactions.py | 2 +- tests/integrations/django/test_transactions.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/sentry_sdk/integrations/django/transactions.py b/sentry_sdk/integrations/django/transactions.py index 91349c4bf9..1532c6f25b 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 6f16d88cec..160da9223d 100644 --- a/tests/integrations/django/test_transactions.py +++ b/tests/integrations/django/test_transactions.py @@ -24,6 +24,9 @@ url(r"^api/(?P(v1|v2))/author/$", lambda x: ""), url(r"^report/", lambda x: ""), url(r"^example/", include(included_url_conf)), + url( + r"^(?P[$\\-_.+!*(),\\w//]+)/$", lambda x: "" + ), # example of complex regex from django-cms ) @@ -53,6 +56,16 @@ def test_legacy_resolver_included_match(): assert result == "/example/foo/bar/{param}" +def test_complex_regex_from_django_cms(): + """ + Reference: https://github.com/getsentry/sentry-python/issues/1527 + """ + + resolver = RavenResolver() + result = resolver.resolve("/,/", example_url_conf) + assert result == "/{slug}/" + + @pytest.mark.skipif(django.VERSION < (2, 0), reason="Requires Django > 2.0") def test_legacy_resolver_newstyle_django20_urlconf(): from django.urls import path