Skip to content

Commit

Permalink
fix: protect against invalid editable data
Browse files Browse the repository at this point in the history
_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.
  • Loading branch information
jdawber authored Oct 31, 2023
1 parent e593486 commit 439c607
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions lib/modules/editable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ export default (blok: SbBlokData) => {
return {};
}

const options = JSON.parse(
blok._editable.replace(/^<!--#storyblok#/, "").replace(/-->$/, "")
);
try {
const options = JSON.parse(
blok._editable.replace(/^<!--#storyblok#/, "").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 {};
}
};

0 comments on commit 439c607

Please sign in to comment.