shuber-attr_encrypted 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ 2009-01-18 - Sean Huber (shuber@huberry.com)
2
+ * Don't attempt to encrypt/decrypt empty strings
3
+
1
4
  2009-01-14 - Sean Huber (shuber@huberry.com)
2
5
  * Move Class logic into Object
3
6
 
@@ -152,8 +152,8 @@ module Huberry
152
152
 
153
153
  define_class_method "encrypt_#{attribute}" do |value|
154
154
  if options[:if] && !options[:unless]
155
- if value.nil?
156
- encrypted_value = nil
155
+ if value.nil? || (value.is_a?(String) && value.empty?)
156
+ encrypted_value = value
157
157
  else
158
158
  value = Marshal.dump(value) if options[:marshal]
159
159
  encrypted_value = options[:encryptor].send options[:encrypt_method], options.merge(:value => value)
@@ -167,8 +167,8 @@ module Huberry
167
167
 
168
168
  define_class_method "decrypt_#{attribute}" do |encrypted_value|
169
169
  if options[:if] && !options[:unless]
170
- if encrypted_value.nil?
171
- decrypted_value = nil
170
+ if encrypted_value.nil? || (encrypted_value.is_a?(String) && encrypted_value.empty?)
171
+ decrypted_value = encrypted_value
172
172
  else
173
173
  encrypted_value = encrypted_value.unpack(options[:encode]).to_s if options[:encode]
174
174
  decrypted_value = options[:encryptor].send(options[:decrypt_method], options.merge(:value => encrypted_value))
@@ -75,6 +75,10 @@ class AttrEncryptedTest < Test::Unit::TestCase
75
75
  assert_nil User.encrypt_email(nil)
76
76
  end
77
77
 
78
+ def test_should_not_encrypt_empty_string
79
+ assert_equal '', User.encrypt_email('')
80
+ end
81
+
78
82
  def test_should_encrypt_email
79
83
  assert_not_nil User.encrypt_email('test@example.com')
80
84
  assert_not_equal 'test@example.com', User.encrypt_email('test@example.com')
@@ -92,6 +96,10 @@ class AttrEncryptedTest < Test::Unit::TestCase
92
96
  assert_nil User.decrypt_email(nil)
93
97
  end
94
98
 
99
+ def test_should_not_decrypt_empty_string
100
+ assert_equal '', User.decrypt_email('')
101
+ end
102
+
95
103
  def test_should_decrypt_email
96
104
  encrypted_email = User.encrypt_email('test@example.com')
97
105
  assert_not_equal 'test@test.com', encrypted_email
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shuber-attr_encrypted
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.7
4
+ version: 1.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Huber