From 439c60770f41d73991d8f3146f2ac0688d3a98f4 Mon Sep 17 00:00:00 2001 From: JD <4291318+jdawber@users.noreply.github.com> Date: Tue, 31 Oct 2023 15:54:30 +0000 Subject: [PATCH] fix: protect against invalid editable data _editable could contain an invalid value, such as null when using graphql. This can cause a exception. This fix prevents issues when the value of _editable is not what is expected. --- lib/modules/editable.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/modules/editable.ts b/lib/modules/editable.ts index 25e88940..109669fb 100644 --- a/lib/modules/editable.ts +++ b/lib/modules/editable.ts @@ -5,16 +5,20 @@ export default (blok: SbBlokData) => { return {}; } - const options = JSON.parse( - blok._editable.replace(/^$/, "") - ); + try { + const options = JSON.parse( + blok._editable.replace(/^$/, "") + ); - if (options) { - return { - "data-blok-c": JSON.stringify(options), - "data-blok-uid": options.id + "-" + options.uid, - }; - } + if (options) { + return { + "data-blok-c": JSON.stringify(options), + "data-blok-uid": options.id + "-" + options.uid, + }; + } - return {}; + return {}; + } catch { + return {}; + } };