From 0ebc00ca9fad75db245cd95ae77166b00d1f6d12 Mon Sep 17 00:00:00 2001 From: Bradley Hilton Date: Mon, 31 Jul 2017 19:12:00 -0500 Subject: [PATCH] Fix #7459, empty attachment arrays causing errors when updating the message --- .../rocketchat-lib/server/methods/updateMessage.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/rocketchat-lib/server/methods/updateMessage.js b/packages/rocketchat-lib/server/methods/updateMessage.js index d55316ff4865..f279bb353d67 100644 --- a/packages/rocketchat-lib/server/methods/updateMessage.js +++ b/packages/rocketchat-lib/server/methods/updateMessage.js @@ -39,12 +39,11 @@ Meteor.methods({ } } - if (originalMessage.attachments) { - if (originalMessage.attachments[0].description !== undefined) { - message.attachments = originalMessage.attachments; - message.attachments[0].description = message.msg; - message.msg = originalMessage.msg; - } + // It is possible to have an empty array as the attachments property, so ensure both things exist + if (originalMessage.attachments && originalMessage.attachments.length > 0 && originalMessage.attachments[0].description !== undefined) { + message.attachments = originalMessage.attachments; + message.attachments[0].description = message.msg; + message.msg = originalMessage.msg; } message.u = originalMessage.u;