From d2293d959211697b1aab152aa26576f973b93a2b Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Tue, 8 May 2018 16:49:58 -0700 Subject: [PATCH] parseAndWriteAvatar: Do shallow copy before omit() call Otherwise, we get all prototype props/functions, which we can't save in IndexedDB --- js/modules/types/contact.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/js/modules/types/contact.js b/js/modules/types/contact.js index 3c484dbf5..12d45bc7e 100644 --- a/js/modules/types/contact.js +++ b/js/modules/types/contact.js @@ -14,14 +14,18 @@ exports.parseAndWriteAvatar = upgradeAttachment => async ( ) => { const { message } = context; const { avatar } = contact; + + // This is to ensure that an omit() call doesn't pull in prototype props/methods + const contactShallowCopy = Object.assign({}, contact); + const contactWithUpdatedAvatar = avatar && avatar.avatar - ? Object.assign({}, contact, { + ? Object.assign({}, contactShallowCopy, { avatar: Object.assign({}, avatar, { avatar: await upgradeAttachment(avatar.avatar, context), }), }) - : omit(contact, ['avatar']); + : omit(contactShallowCopy, ['avatar']); // eliminates empty numbers, emails, and addresses; adds type if not provided const parsedContact = parseContact(contactWithUpdatedAvatar);