Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions src/sentry/grouping/parameterization.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ class ParameterizationRegex:
name: str # name of the pattern (also used as group name in combined regex)
raw_pattern: str # regex pattern w/o matching group name
raw_pattern_experimental: str | None = None
lookbehind: str | None = None # positive lookbehind prefix if needed
lookahead: str | None = None # positive lookahead postfix if needed
# Function which takes the matched value and returns the replacement value.
replacement_callback: ParameterizationReplacementFunction | None = None

Expand All @@ -38,11 +36,9 @@ def experimental_pattern(self) -> str | None:

def _get_pattern(self, raw_pattern: str) -> str:
"""
Returns the regex pattern with a named matching group and lookbehind/lookahead if needed.
Returns the regex pattern inside of a named matching group.
"""
prefix = rf"(?<={self.lookbehind})" if self.lookbehind else ""
postfix = rf"(?={self.lookahead})" if self.lookahead else ""
return rf"{prefix}(?P<{self.name}>{raw_pattern}){postfix}"
return rf"(?P<{self.name}>{raw_pattern})"


def is_valid_ip(maybe_ip_str: str) -> bool:
Expand Down Expand Up @@ -311,23 +307,25 @@ def is_valid_ip(maybe_ip_str: str) -> bool:
ParameterizationRegex(
name="quoted_str",
raw_pattern=r"""
'([^']+)' | "([^"]+)"
# Lookbehind to ensure we'll only match the value half of `<key>=<value>`-type key-value
# pairs, rather than all quoted strings
(?<=[=])
(
'([^']+)' |
"([^"]+)"
)
""",
# Using an `=` lookbehind guarantees we'll only match the value half of key-value pairs,
# rather than all quoted strings
lookbehind="=",
),
ParameterizationRegex(
name="bool",
raw_pattern=r"""
True |
true |
False |
false
# Lookbehind to ensure we'll only match the value half of `<key>=<value>`-type key-value
# pairs, rather than all instances of the words 'true' and 'false'
(?<=[=])
(
True | true | False | false
)
""",
# Using an `=` lookbehind guarantees we'll only match the value half of key-value pairs,
# rather than all instances of the words 'true' and 'false'.
lookbehind="=",
),
]

Expand Down
Loading