Skip to content

Commit

Permalink
Don't dig. (#128)
Browse files Browse the repository at this point in the history
`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
  • Loading branch information
jankoegel authored Oct 23, 2023
1 parent 1b70b6e commit 984ef59
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/invisible_captcha/controller_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 984ef59

Please sign in to comment.