From 984ef59ebe37559a7d467f066125c29e680b86e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20K=C3=B6gel?= <100707419+jankoegel@users.noreply.github.com> Date: Tue, 24 Oct 2023 01:21:14 +0200 Subject: [PATCH] Don't dig. (#128) `dig` throws a `TypeError` exception when `params[scope]` is set (e.g. to a string). Example this works: ```ruby params = { actor: { name: "Nicolas Cage" } } # digging with keys that don't exist params.dig(:foo, :bar) => nil # digging with keys that partially exist params.dig(:actor, :name, :whatever) => TypeError: String does not have #dig method ``` Full article: http://anamaria.martinezgomez.name/2018/01/07/ruby-dig.html Original discussion: https://bugs.ruby-lang.org/issues/11762 --- lib/invisible_captcha/controller_ext.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/invisible_captcha/controller_ext.rb b/lib/invisible_captcha/controller_ext.rb index 2c72e90..e51330d 100644 --- a/lib/invisible_captcha/controller_ext.rb +++ b/lib/invisible_captcha/controller_ext.rb @@ -89,7 +89,7 @@ def honeypot_spam?(options = {}) # If honeypot is defined for this controller-action, search for: # - honeypot: params[:subtitle] # - honeypot with scope: params[:topic][:subtitle] - if params[honeypot].present? || params.dig(scope, honeypot).present? + if params[honeypot].present? || (params[scope] && params[scope][honeypot].present?) warn_spam("Honeypot param '#{honeypot}' was present.") return true else @@ -99,7 +99,7 @@ def honeypot_spam?(options = {}) end else InvisibleCaptcha.honeypots.each do |default_honeypot| - if params[default_honeypot].present? || params.dig(scope, default_honeypot).present? + if params[default_honeypot].present? || (params[scope] && params[scope][default_honeypot].present?) warn_spam("Honeypot param '#{scope}.#{default_honeypot}' was present.") return true end