From 31719bece1a3446d1a905d9b32b9088cd2bfdc3a Mon Sep 17 00:00:00 2001 From: georgel-pop-lr Date: Mon, 18 May 2020 13:38:57 +0200 Subject: [PATCH] fix: gracefully handle invalid JSON in data-style attribute (#1393): --- src/plugins/embedurl.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/plugins/embedurl.js b/src/plugins/embedurl.js index ee68d5a7a2..d51f3d2f6a 100644 --- a/src/plugins/embedurl.js +++ b/src/plugins/embedurl.js @@ -406,11 +406,21 @@ if (!CKEDITOR.plugins.get('embedurl')) { // Sync dimensions and alignment with editor wrapper + let styles = null; + const stylesJSON = instance.element.getAttribute( 'data-styles' ); - let styles = stylesJSON ? JSON.parse(stylesJSON) : null; + if (stylesJSON) { + try { + styles = JSON.parse(stylesJSON); + } catch (e) { + console.warn( + 'Unable to parse data-styles attribute!' + ); + } + } if (!styles) { const iframe = instance.wrapper.findOne('iframe');