Skip to content

Commit

Permalink
Merge pull request #529 from tbussmann/patch-reset-matches
Browse files Browse the repository at this point in the history
reset matches when testing an empty UA
  • Loading branch information
JayBizzle authored Jun 7, 2024
2 parents e9f5cdd + f0f29f5 commit 8724b91
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/CrawlerDetect.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ public function isCrawler($userAgent = null)
));

if ($agent === '') {
$this->matches = array();
return false;
}

Expand Down
10 changes: 10 additions & 0 deletions tests/UserAgentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ public function matches_does_not_persit_across_multiple_calls()
$this->CrawlerDetect->isCrawler('This should not match');
$matches = $this->CrawlerDetect->getMatches();
$this->assertNull($this->CrawlerDetect->getMatches());

//Empty
$this->CrawlerDetect->isCrawler('Mozilla/5.0 (iPhone; CPU iPhone OS 7_1 like Mac OS X) AppleWebKit (KHTML, like Gecko) Mobile (compatible; Yahoo Ad monitoring; https://help.yahoo.com/kb/yahoo-ad-monitoring-SLN24857.html)');
$this->CrawlerDetect->isCrawler('');
$this->assertNull($this->CrawlerDetect->getMatches());

//Excluded
$this->CrawlerDetect->isCrawler('Mozilla/5.0 (iPhone; CPU iPhone OS 7_1 like Mac OS X) AppleWebKit (KHTML, like Gecko) Mobile (compatible; Yahoo Ad monitoring; https://help.yahoo.com/kb/yahoo-ad-monitoring-SLN24857.html)');
$this->CrawlerDetect->isCrawler('iPod');
$this->assertNull($this->CrawlerDetect->getMatches());
}

/** @test */
Expand Down

0 comments on commit 8724b91

Please sign in to comment.