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

Fix file restore when the file is empty

GitOrigin-RevId: be08305c9a41265acfb12046aeb2d003cda92b54
This commit is contained in:
Eric Mc Sween 2024-07-05 11:57:26 -04:00 committed by Copybot
parent fbdf245517
commit 58ffefc8bb
2 changed files with 20 additions and 1 deletions

View file

@ -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()

View file

@ -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: [],
})
})
})
})
})