Validate and compile the user agent filter pattern once - #40
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #40 +/- ##
============================================
+ Coverage 62.40% 67.99% +5.59%
- Complexity 129 134 +5
============================================
Files 30 30
Lines 375 403 +28
============================================
+ Hits 234 274 +40
+ Misses 141 129 -12 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
loevgaard
force-pushed
the
fix/20-fbc-cookie-format
branch
from
September 7, 2026 11:37
d21eff5 to
0e4216b
Compare
loevgaard
force-pushed
the
fix/18-user-agent-regex
branch
from
September 7, 2026 11:37
d55fb32 to
2555afe
Compare
loevgaard
force-pushed
the
fix/20-fbc-cookie-format
branch
from
September 7, 2026 12:03
0e4216b to
812c650
Compare
loevgaard
force-pushed
the
fix/18-user-agent-regex
branch
from
September 7, 2026 12:03
2555afe to
2809b78
Compare
An invalid fragment, or one containing an unescaped delimiter, made preg_match() return false instead of 1, so the filter silently stopped filtering. Compile the pattern once in the constructor, validate each fragment at compile time, and match case insensitively. Fixes #18
loevgaard
force-pushed
the
fix/18-user-agent-regex
branch
from
September 7, 2026 12:18
2809b78 to
1b06004
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #18
Problem
FilterConfiguredUserAgentsSubscriberbuilt'#' . implode('|', $userAgents) . '#'on every event and compared the result ofpreg_match()with=== 1.An invalid fragment, or one containing a
#, makespreg_match()emit a warning and returnfalse, which is not1, so the filter silently stops filtering.foo#baris the nastiest case: it closes the delimiter and turnsbarinto modifiers. Nothing failed, nothing was logged, bots simply started being tracked again.Matching was also case sensitive, while the same crawler shows up in different casings.
Change
\InvalidArgumentExceptionat container build time instead of failing open at runtime.Configuration, so the error surfaces as a normal configuration error naming the offending fragment and reminding you to escape#.imodifier is added, and the option is documented as case insensitive.Tests
Six unit tests (match, no match, case insensitive match, no user agent, no fragments configured, and both invalid-pattern constructor throws) plus two extension tests asserting the configuration is rejected.