From 9323caf2f16ffc4812ff6c9717555f696e1b81a8 Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Sun, 20 Jun 2021 13:59:58 +0100 Subject: [PATCH] Fixed revision issue for old revisions --- packages/lib/models/Revision.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/lib/models/Revision.ts b/packages/lib/models/Revision.ts index 11ff38045..57d6c708e 100644 --- a/packages/lib/models/Revision.ts +++ b/packages/lib/models/Revision.ts @@ -45,7 +45,10 @@ export default class Revision extends BaseItem { if (this.isLegacyPatch(patch)) { return this.applyTextPatchLegacy(text, patch); } else { - const result = dmp.patch_apply(JSON.parse(patch), text); + // An empty patch should be '[]', but legacy data may be just "". + // However an empty string would make JSON.parse fail so we set it + // to '[]'. + const result = dmp.patch_apply(JSON.parse(patch ? patch : '[]'), text); if (!result || !result.length) throw new Error('Could not apply patch'); return result[0]; }