Skip to content

Commit

Permalink
reset matches when testing an empty UA
Browse files Browse the repository at this point in the history
Make sure, getMatches will not return stale data if the last test was
performed for an empty UA or only consists of excluded patterns.
  • Loading branch information
tbussmann committed May 30, 2024
1 parent e9f5cdd commit f0f29f5
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 f0f29f5

Please sign in to comment.