ankane / lockbox

Modern encryption for Ruby and Rails
MIT License
1.46k stars 68 forks source link

Empty hash is encrypted as nil #160

Closed dimerman closed 2 years ago

dimerman commented 2 years ago

I'm using lockbox@1.0.0 This looks similar to https://github.com/ankane/lockbox/issues/109 and according to the changelog this was addressed on version 0.6.3. maybe it's a regression?

I have a field defined as:

  has_encrypted :words, type: :hash

Actual behaviour:

> my_object
=> #<MyClass words: nil, ...>

0> my_object.update(words: {})
=> {}

0> my_object
=> #<MyClass words: nil, ...>

Expected behaviour: I'd expect to retrieve an empty hash if I previously set an empty hash.

ankane commented 2 years ago

Hey @dimerman, can you use this gist to reproduce?

dimerman commented 2 years ago

hello @ankane forked the gist and updated it here: https://gist.github.com/dimerman/ce7e1e50b0ef1bf4f248d6de02e0f2bb

(results inside)

thanks!

ankane commented 2 years ago

Thanks. However, it looks like it is returning an empty hash on line 36.