Przeglądaj źródła

Merge pull request #19298 from overleaf/em-fix-restore-empty-file

Fix file restore when the file is empty

GitOrigin-RevId: be08305c9a41265acfb12046aeb2d003cda92b54
Eric Mc Sween 2 lat temu
rodzic
commit
58ffefc8bb

+ 1 - 1
services/project-history/app/js/SnapshotManager.js

@@ -78,7 +78,7 @@ async function getRangesSnapshot(projectId, version, pathname) {
   const historyId = await WebApiManager.promises.getHistoryId(projectId)
   await file.load('eager', HistoryStoreManager.getBlobStore(historyId))
   const content = file.getContent()
-  if (!content) {
+  if (content == null) {
     throw new Error('Unable to read file contents')
   }
   const trackedChanges = file.getTrackedChanges().asSorted()

+ 19 - 0
services/project-history/test/unit/js/SnapshotManager/SnapshotManagerTests.js

@@ -978,5 +978,24 @@ Four five six\
         })
       })
     })
+
+    describe('with an empty file', function () {
+      beforeEach(async function () {
+        this.getString.resolves('')
+        this.getObject.resolves({})
+        this.data = await this.SnapshotManager.promises.getRangesSnapshot(
+          this.projectId,
+          1,
+          'main.tex'
+        )
+      })
+
+      it('should return empty comments and changes', function () {
+        expect(this.data).to.deep.equal({
+          changes: [],
+          comments: [],
+        })
+      })
+    })
   })
 })