From 58017d44806a926ca58a39146a3e3901515e952d Mon Sep 17 00:00:00 2001 From: Eric Mc Sween Date: Thu, 5 Mar 2020 11:36:12 -0500 Subject: [PATCH] Merge pull request #2659 from overleaf/em-binary-file-history-fix Fix binary file diffs GitOrigin-RevId: 1773e8918a0f82a1945470630ca691dfa4b13026 --- services/web/app/src/Features/History/HistoryManager.js | 9 +++++++-- .../web/test/unit/src/History/HistoryManagerTests.js | 7 +++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/services/web/app/src/Features/History/HistoryManager.js b/services/web/app/src/Features/History/HistoryManager.js index 1149b3e558..5ddebb5f73 100644 --- a/services/web/app/src/Features/History/HistoryManager.js +++ b/services/web/app/src/Features/History/HistoryManager.js @@ -112,7 +112,12 @@ async function injectUserDetails(data) { // service. v1 ids will be `numbers` let userIds = new Set() let v1UserIds = new Set() - for (const entry of data.diff || data.updates || []) { + const entries = Array.isArray(data.diff) + ? data.diff + : Array.isArray(data.updates) + ? data.updates + : [] + for (const entry of entries) { for (const user of (entry.meta && entry.meta.users) || []) { if (typeof user === 'string') { userIds.add(user) @@ -138,7 +143,7 @@ async function injectUserDetails(data) { for (const user of v1IdentifiedUsersArray) { users[user.overleaf.id] = _userView(user) } - for (const entry of data.diff || data.updates || []) { + for (const entry of entries) { if (entry.meta != null) { entry.meta.users = ((entry.meta && entry.meta.users) || []).map(user => { if (typeof user === 'string' || typeof user === 'number') { diff --git a/services/web/test/unit/src/History/HistoryManagerTests.js b/services/web/test/unit/src/History/HistoryManagerTests.js index c3f9eda40c..3554d15c59 100644 --- a/services/web/test/unit/src/History/HistoryManagerTests.js +++ b/services/web/test/unit/src/History/HistoryManagerTests.js @@ -195,6 +195,13 @@ describe('HistoryManager', function() { expect(diff.diff[0].meta.users).to.deep.equal([this.user1_view]) expect(diff.diff[1].meta.users).to.deep.equal([this.user2_view]) }) + + it('should handle a binary diff marker', async function() { + const diff = await this.HistoryManager.promises.injectUserDetails({ + diff: { binary: true } + }) + expect(diff.diff.binary).to.be.true + }) }) describe('with a list of updates', function() {