Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(integrations): support complex regex coming from DjangoCMS #1773

Merged
merged 2 commits into from Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/django/transactions.py
Expand Up @@ -37,7 +37,7 @@

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+)>.*\)")

Check warning on line 40 in sentry_sdk/integrations/django/transactions.py

View check run for this annotation

Codecov / codecov/patch

sentry_sdk/integrations/django/transactions.py#L40

Added line #L40 was not covered by tests
_non_named_group_matcher = re.compile(r"\([^\)]+\)")
# [foo|bar|baz]
_either_option_matcher = re.compile(r"\[([^\]]+)\|([^\]]+)\]")
Expand Down
13 changes: 13 additions & 0 deletions tests/integrations/django/test_transactions.py
Expand Up @@ -24,6 +24,9 @@
url(r"^api/(?P<version>(v1|v2))/author/$", lambda x: ""),
url(r"^report/", lambda x: ""),
url(r"^example/", include(included_url_conf)),
url(
r"^(?P<slug>[$\\-_.+!*(),\\w//]+)/$", lambda x: ""
), # example of complex regex from django-cms
)


Expand Down Expand Up @@ -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
Expand Down