From b7e061436219fbdf036ec3c2afa10b3bab92e5d6 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Wed, 30 Jan 2019 14:44:53 +0000 Subject: [PATCH] Added `undefined` guards to uses of JSON stringify/parse copying no issue - added guards for JSON stringify+parse replacements of `Ember.copy` introduced in https://github.com/TryGhost/Ghost-Admin/commit/6fe40b941bba251823766430787b3dae5cf2c94f --- ghost/admin/app/controllers/editor.js | 2 +- ghost/admin/lib/koenig-editor/addon/components/koenig-editor.js | 2 +- .../lib/koenig-editor/addon/components/koenig-slash-menu.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ghost/admin/app/controllers/editor.js b/ghost/admin/app/controllers/editor.js index 91581b6dc7..bf5c69aab5 100644 --- a/ghost/admin/app/controllers/editor.js +++ b/ghost/admin/app/controllers/editor.js @@ -318,7 +318,7 @@ export default Controller.extend({ // set mobiledoc equal to what's in the editor but create a copy so that // nested objects/arrays don't keep references which can mean that both // scratch and mobiledoc get updated simultaneously - this.set('post.mobiledoc', JSON.parse(JSON.stringify(this.post.scratch))); + this.set('post.mobiledoc', JSON.parse(JSON.stringify(this.post.scratch || null))); this.set('post.status', status); // Set a default title diff --git a/ghost/admin/lib/koenig-editor/addon/components/koenig-editor.js b/ghost/admin/lib/koenig-editor/addon/components/koenig-editor.js index 4673c8a81c..55b81c5b6b 100644 --- a/ghost/admin/lib/koenig-editor/addon/components/koenig-editor.js +++ b/ghost/admin/lib/koenig-editor/addon/components/koenig-editor.js @@ -312,7 +312,7 @@ export default Component.extend({ // `payload.files` is special because it's set by paste/drag-n-drop // events and can't be copied for security reasons let {files} = payload; - let payloadCopy = JSON.parse(JSON.stringify(payload)); + let payloadCopy = JSON.parse(JSON.stringify(payload || null)); payloadCopy.files = files; // all of the properties that will be passed through to the diff --git a/ghost/admin/lib/koenig-editor/addon/components/koenig-slash-menu.js b/ghost/admin/lib/koenig-editor/addon/components/koenig-slash-menu.js index 9bfdb089d2..31584ec092 100644 --- a/ghost/admin/lib/koenig-editor/addon/components/koenig-slash-menu.js +++ b/ghost/admin/lib/koenig-editor/addon/components/koenig-slash-menu.js @@ -163,7 +163,7 @@ export default Component.extend({ }).compact(); // we need a copy to avoid modifying the object references - let sections = JSON.parse(JSON.stringify(matchedItems)); + let sections = JSON.parse(JSON.stringify(matchedItems || [])); if (sections.length) { set(sections[0].items[0], 'selected', true);