From 5cebce9bbf557dd5079902d4bcdb5fd34b1caf41 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 22 Aug 2019 14:41:40 +0100 Subject: [PATCH] fix bug detected by tests --- src/editor/deserialize.js | 8 ++++---- test/editor/deserialize-test.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/editor/deserialize.js b/src/editor/deserialize.js index d5efef5d1a..d59e4ca123 100644 --- a/src/editor/deserialize.js +++ b/src/editor/deserialize.js @@ -223,14 +223,14 @@ function parseHtmlMessage(html, partCreator, isQuotedMessage) { function parsePlainTextMessage(body, partCreator, isQuotedMessage) { const lines = body.split("\n"); const parts = lines.reduce((parts, line, i) => { - const isLast = i === lines.length - 1; - if (!isLast) { - parts.push(partCreator.newline()); - } if (isQuotedMessage) { parts.push(partCreator.plain(QUOTE_LINE_PREFIX)); } parts.push(...parseAtRoomMentions(line, partCreator)); + const isLast = i === lines.length - 1; + if (!isLast) { + parts.push(partCreator.newline()); + } return parts; }, []); return parts; diff --git a/test/editor/deserialize-test.js b/test/editor/deserialize-test.js index 46deb14ce3..8a79b4101f 100644 --- a/test/editor/deserialize-test.js +++ b/test/editor/deserialize-test.js @@ -71,10 +71,10 @@ describe('editor/deserialize', function() { describe('text messages', function() { it('test with newlines', function() { const parts = normalize(parseEvent(textMessage("hello\nworld"), createPartCreator())); - expect(parts.length).toBe(3); expect(parts[0]).toStrictEqual({type: "plain", text: "hello"}); expect(parts[1]).toStrictEqual({type: "newline", text: "\n"}); expect(parts[2]).toStrictEqual({type: "plain", text: "world"}); + expect(parts.length).toBe(3); }); it('@room pill', function() { const parts = normalize(parseEvent(textMessage("text message for @room"), createPartCreator()));