Просмотр исходного кода

Merge pull request #2659 from overleaf/em-binary-file-history-fix

Fix binary file diffs

GitOrigin-RevId: 1773e8918a0f82a1945470630ca691dfa4b13026
Eric Mc Sween 6 лет назад
Родитель
Сommit
58017d4480

+ 7 - 2
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') {

+ 7 - 0
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() {