From 66fdc07a0bc885651e7b2ca4743874adb374e0dc Mon Sep 17 00:00:00 2001 From: Robert Graff Date: Mon, 3 Aug 2020 11:30:46 -0700 Subject: [PATCH 1/2] allow is_crawler? & crawler_name to be called outside of rack When `is_crawler?` is called outside the content of a rack request--for example in specs--it will raise an error. This prevents that. --- lib/rack/crawler_detect.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/rack/crawler_detect.rb b/lib/rack/crawler_detect.rb index b19f29a..075689f 100644 --- a/lib/rack/crawler_detect.rb +++ b/lib/rack/crawler_detect.rb @@ -8,11 +8,11 @@ class CrawlerDetect def initialize(app, options = {}) Rack::Request::Helpers.module_eval do def is_crawler? - env["rack.crawler_detect"][:is_crawler] + env["rack.crawler_detect"] && env["rack.crawler_detect"][:is_crawler] end def crawler_name - env["rack.crawler_detect"][:crawler_name] + env["rack.crawler_detect"] && env["rack.crawler_detect"][:crawler_name] end end @app = app From d18968906b5989c223cbef80d5655ac1d2670c10 Mon Sep 17 00:00:00 2001 From: Robert Graff Date: Thu, 5 Nov 2020 15:27:22 -0800 Subject: [PATCH 2/2] ensure `is_crawler?` returns true or false --- lib/rack/crawler_detect.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rack/crawler_detect.rb b/lib/rack/crawler_detect.rb index 075689f..522ed47 100644 --- a/lib/rack/crawler_detect.rb +++ b/lib/rack/crawler_detect.rb @@ -8,7 +8,7 @@ class CrawlerDetect def initialize(app, options = {}) Rack::Request::Helpers.module_eval do def is_crawler? - env["rack.crawler_detect"] && env["rack.crawler_detect"][:is_crawler] + !!(env["rack.crawler_detect"] && env["rack.crawler_detect"][:is_crawler]) end def crawler_name