From bc8cc56a2ae0b73276782d66b7dceba1ecd294a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Tue, 2 Dec 2014 13:10:18 -0200 Subject: Prefer object/nil over `true`/`false` This is the project guideline and the reasons are: * That follows standard Ruby semantics. * Allows the implementation to avoid artificial code like !! or something ? true : false * You do not need to rely on the exact type of 3rd party code. For example, if your method returns str.end_with?('foo') you do not need to make sure end_with? returns a singleton. Your predicate just propagates predicate semantics up regardless of what end_with? returns. --- activesupport/lib/active_support/message_verifier.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/message_verifier.rb b/activesupport/lib/active_support/message_verifier.rb index 8e5d050540..97fb994cff 100644 --- a/activesupport/lib/active_support/message_verifier.rb +++ b/activesupport/lib/active_support/message_verifier.rb @@ -35,8 +35,8 @@ module ActiveSupport end def valid_message?(signed_message) - return false if signed_message.blank? - + return if signed_message.blank? + data, digest = signed_message.split("--") data.present? && digest.present? && ActiveSupport::SecurityUtils.secure_compare(digest, generate_digest(data)) end @@ -47,14 +47,12 @@ module ActiveSupport data = signed_message.split("--")[0] @serializer.load(decode(data)) rescue ArgumentError => argument_error - return false if argument_error.message =~ %r{invalid base64} + return if argument_error.message =~ %r{invalid base64} raise end - else - false end end - + def verify(signed_message) verified(signed_message) || raise(InvalidSignature) end -- cgit v1.2.3