Skip to content

Commit 8fea000

Browse files
authored
fix: support any regex delimiter and modifiers in compiler pass pattern matching (#2212)
Use @preg_match with error suppression to detect valid regex patterns instead of checking for '/' delimiters, supporting any delimiter and modifiers, consistent with the rest of the telemetry-bundle.
1 parent 8e6d159 commit 8fea000

4 files changed

Lines changed: 16 additions & 8 deletions

File tree

src/bridge/symfony/telemetry-bundle/src/Flow/Bridge/Symfony/TelemetryBundle/DependencyInjection/Compiler/CacheTelemetryPass.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ private function isExcluded(string $serviceId, array $patterns) : bool
8181

8282
private function matchesPattern(string $serviceId, string $pattern) : bool
8383
{
84-
if (\str_starts_with($pattern, '/') && \str_ends_with($pattern, '/')) {
85-
return (bool) \preg_match($pattern, $serviceId);
84+
$result = @\preg_match($pattern, $serviceId);
85+
86+
if ($result !== false) {
87+
return (bool) $result;
8688
}
8789

8890
return $serviceId === $pattern;

src/bridge/symfony/telemetry-bundle/src/Flow/Bridge/Symfony/TelemetryBundle/DependencyInjection/Compiler/DBALTelemetryPass.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,10 @@ private function isExcluded(string $connectionName, array $patterns) : bool
9999

100100
private function matchesPattern(string $connectionName, string $pattern) : bool
101101
{
102-
if (\str_starts_with($pattern, '/') && \str_ends_with($pattern, '/')) {
103-
return (bool) \preg_match($pattern, $connectionName);
102+
$result = @\preg_match($pattern, $connectionName);
103+
104+
if ($result !== false) {
105+
return (bool) $result;
104106
}
105107

106108
return $connectionName === $pattern;

src/bridge/symfony/telemetry-bundle/src/Flow/Bridge/Symfony/TelemetryBundle/DependencyInjection/Compiler/HttpClientTelemetryPass.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ private function isExcluded(string $serviceId, array $patterns) : bool
6262

6363
private function matchesPattern(string $serviceId, string $pattern) : bool
6464
{
65-
if (\str_starts_with($pattern, '/') && \str_ends_with($pattern, '/')) {
66-
return (bool) \preg_match($pattern, $serviceId);
65+
$result = @\preg_match($pattern, $serviceId);
66+
67+
if ($result !== false) {
68+
return (bool) $result;
6769
}
6870

6971
return $serviceId === $pattern;

src/bridge/symfony/telemetry-bundle/src/Flow/Bridge/Symfony/TelemetryBundle/DependencyInjection/Compiler/Psr18ClientTelemetryPass.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,10 @@ private function isExcluded(string $serviceId, array $patterns) : bool
8383

8484
private function matchesPattern(string $serviceId, string $pattern) : bool
8585
{
86-
if (\str_starts_with($pattern, '/') && \str_ends_with($pattern, '/')) {
87-
return (bool) \preg_match($pattern, $serviceId);
86+
$result = @\preg_match($pattern, $serviceId);
87+
88+
if ($result !== false) {
89+
return (bool) $result;
8890
}
8991

9092
return $serviceId === $pattern;

0 commit comments

Comments
 (0)