generalpiston / typeorm-encrypted

Encrypted field for typeorm.
MIT License
75 stars 19 forks source link

transformer does not work on null fields #27

Closed andreo-k closed 4 years ago

andreo-k commented 4 years ago

fixed the issue. pls merge in my pull-request

generalpiston commented 4 years ago

Is the issue that the transformer doesn't work if NULL values are provided?

andreo-k commented 4 years ago

well, yes and no. I use typeorm-encrypted with typeorm and mysql. And when there is null in column, typeorm sends '' (empty string) to the 'to' method. Then encryptor fails.

generalpiston commented 4 years ago

Hmmm so I just tested null and undefined values out for the transformer. It works as it should. Basically, any null or undefined value in the entity shouldn't be transformed. Empty strings should be transformed/encrypted.

Just to be sure, are you passing null or undefined as the value for that column in the entity? Also, If the to method is receiving an empty string, then you're likely providing an empty string to the entity instead of null or undefined.

Otherwise, this could be an issue specifically with the MySQL handler in Typeorm rather than typeorm-encrypted.

I'll follow up with them as well... stay tuned :).

andreo-k commented 4 years ago

are you passing null or undefined

well, I am passing null, then save the entity with typeorm, then see the entity record in my sql with the NULL, then read the entity with typeorm and typeorm-encrypted gets '' into the to method. Yes probably it is typeorm + mysql issue, that it passes '' when there is actually NULL, but in any case typeorm-encrypted does not work on ''.

generalpiston commented 4 years ago

Oh, if it's on the read side, then that should be fine.

generalpiston commented 4 years ago

@andreo-k I added a couple of notes. Basically, on the save side, no changes are needed. On the read side, your change works.

andreo-k commented 4 years ago

@generalpiston I removed changes from 'save' side, pushed to same branch

generalpiston commented 4 years ago

Merged. Thanks @andreo-k . I'll create a new release too.

generalpiston commented 4 years ago

Version 0.5.6 has this patch @andreo-k .