mirror of
https://github.com/heartcombo/devise.git
synced 2026-04-06 03:01:21 -04:00
Call respond_to?(attr) before applying strip or downcase
This avoids calling strip and downcase on globally configured keys that may not exist on all devise models. Fixes #2204, a regression introduced by PR #2135. Also included a note about the intentional use of respond_to.
This commit is contained in:
@@ -168,7 +168,16 @@ module Devise
|
||||
end
|
||||
|
||||
def apply_to_attribute_or_variable(attr, method)
|
||||
(self[attr] || send(attr)).try(method)
|
||||
if self[attr]
|
||||
self[attr].try(method)
|
||||
|
||||
# Use respond_to? here to avoid a regression where globally
|
||||
# configured strip_whitespace_keys or case_insensitive_keys were
|
||||
# attempting to strip! or downcase! when a model didn't have the
|
||||
# globally configured key.
|
||||
elsif respond_to?(attr)
|
||||
send(attr).try(method)
|
||||
end
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
|
||||
Reference in New Issue
Block a user