Skip to content

Fix bugs and harden tests (patch-safe)#595

Merged
JayBizzle merged 3 commits intomasterfrom
updates
Apr 14, 2026
Merged

Fix bugs and harden tests (patch-safe)#595
JayBizzle merged 3 commits intomasterfrom
updates

Conversation

@JayBizzle
Copy link
Copy Markdown
Owner

@JayBizzle JayBizzle commented Mar 24, 2026

Patch-safe bug fixes and test improvements. No public API or signature changes, suitable for a point release.

Bug fixes

  • Fix null concatenation deprecation in setUserAgent() (PHP 8.1+)
  • Fix MSIE exclusion pattern missing * quantifier
  • Reset $matches at top of isCrawler() so stale matches don't leak across calls
  • Add preg_match/preg_replace error handling in isCrawler()
  • Default $httpHeaders / $userAgent parameters to null on setHttpHeaders() / setUserAgent() for ergonomic parity with the constructor

Test improvements

  • Use setUp() to instantiate CrawlerDetect once per test
  • Rename test property to $crawlerDetect and make it protected
  • Fix typo in test method name (persit -> persist)
  • Optimise collision test from O(n²) to O(n²/2)
  • Add test that regex patterns are all valid
  • Add test that isCrawler($ua) does not mutate the stored user agent

Deferred to next major

Type declarations, return types and the compileRegex() visibility change have been dropped from this PR — they'll be bundled into the next major release.

JayBizzle and others added 2 commits March 24, 2026 20:07
- Fix null concatenation deprecation in setUserAgent (PHP 8.1+)
- Fix MSIE exclusion pattern missing * quantifier
- Reset matches at top of isCrawler() for reliable state
- Add preg error handling in isCrawler()
- Make compileRegex() protected (internal API)
- Add return type declarations to all methods
- Add parameter type hints throughout
- Use setUp() in tests, fix property visibility/naming
- Fix typo in test method name (persit -> persist)
- Optimize collision test from O(n²) to O(n²/2)
- Add tests for regex validity and stored agent immutability
Keeps the bug fixes and deprecation fix in isCrawler()/setUserAgent()
and the MSIE exclusion pattern fix, but drops the param/return type
declarations and the compileRegex() visibility change so this can ship
as a patch release.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@JayBizzle JayBizzle changed the title Improve code quality: fix bugs, add type safety, and harden tests Fix bugs and harden tests (patch-safe) Apr 14, 2026
Forces preg_match to return PREG_BACKTRACK_LIMIT_ERROR by setting
pcre.backtrack_limit to 1, covering the previously untested error path.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@JayBizzle JayBizzle merged commit 27b1342 into master Apr 14, 2026
10 checks passed
@JayBizzle JayBizzle deleted the updates branch April 14, 2026 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant