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:
Drew Ulmer
2013-01-09 11:42:54 -06:00
parent c768366240
commit 75ce916be9

View File

@@ -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