From f0f29f57d8a9ca154b865ea30e78ede45e0a6455 Mon Sep 17 00:00:00 2001 From: Tobias Bussmann Date: Thu, 30 May 2024 18:23:37 +0200 Subject: [PATCH] reset matches when testing an empty UA Make sure, getMatches will not return stale data if the last test was performed for an empty UA or only consists of excluded patterns. --- src/CrawlerDetect.php | 1 + tests/UserAgentTest.php | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/src/CrawlerDetect.php b/src/CrawlerDetect.php index 3ea284a..48961d1 100644 --- a/src/CrawlerDetect.php +++ b/src/CrawlerDetect.php @@ -169,6 +169,7 @@ public function isCrawler($userAgent = null) )); if ($agent === '') { + $this->matches = array(); return false; } diff --git a/tests/UserAgentTest.php b/tests/UserAgentTest.php index dd6f265..21bf029 100644 --- a/tests/UserAgentTest.php +++ b/tests/UserAgentTest.php @@ -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 */