mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-24 19:33:02 +03:00
🐛 Fixed editor crashing with unknown cards in mobiledoc (#16430)
refs TryGhost/Team#2702 - adds a default handler for unknown cards: - logs a warning message to the console - removes the card from the mobiledoc
This commit is contained in:
parent
74a1ab4525
commit
8d4028bbb7
@ -189,7 +189,12 @@ export default class KoenigEditor extends Component {
|
|||||||
spellcheck: this.spellcheck,
|
spellcheck: this.spellcheck,
|
||||||
autofocus: this.autofocus,
|
autofocus: this.autofocus,
|
||||||
atoms,
|
atoms,
|
||||||
cards
|
cards,
|
||||||
|
unknownCardHandler: ({env}) => {
|
||||||
|
console.warn(`Unknown card encountered: ${env.name}`); //eslint-disable-line
|
||||||
|
|
||||||
|
env.remove();
|
||||||
|
}
|
||||||
}, options);
|
}, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -807,7 +812,7 @@ export default class KoenigEditor extends Component {
|
|||||||
// refresh drag/drop
|
// refresh drag/drop
|
||||||
// TODO: can be made more performant by only refreshing when droppable
|
// TODO: can be made more performant by only refreshing when droppable
|
||||||
// order changes or when sections are added/removed
|
// order changes or when sections are added/removed
|
||||||
this._cardDragDropContainer.refresh();
|
this._cardDragDropContainer?.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
cursorDidChange(editor) {
|
cursorDidChange(editor) {
|
||||||
|
@ -632,5 +632,75 @@ describe('Acceptance: Editor', function () {
|
|||||||
|
|
||||||
// no expects, will throw with an error and fail when it hits the bug
|
// no expects, will throw with an error and fail when it hits the bug
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// https://github.com/TryGhost/Team/issues/2702
|
||||||
|
it('removes unknown cards instead of crashing', async function () {
|
||||||
|
let post = this.server.create('post', {authors: [author], status: 'published', title: 'Title', mobiledoc: JSON.stringify({
|
||||||
|
version: '0.3.1',
|
||||||
|
atoms: [],
|
||||||
|
cards: [
|
||||||
|
[
|
||||||
|
'asdfadsfasdfasdfadsf',
|
||||||
|
{
|
||||||
|
cardWidth: 'wide',
|
||||||
|
startingPosition: 50,
|
||||||
|
caption: 'Salmon On The Grill: BEFORE / AFTER'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
markups: [],
|
||||||
|
sections: [
|
||||||
|
[
|
||||||
|
1,
|
||||||
|
'p',
|
||||||
|
[
|
||||||
|
[
|
||||||
|
0,
|
||||||
|
[],
|
||||||
|
0,
|
||||||
|
'Paragraph 1'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
10,
|
||||||
|
0
|
||||||
|
]
|
||||||
|
],
|
||||||
|
ghostVersion: '4.0'
|
||||||
|
})});
|
||||||
|
|
||||||
|
await visit(`/editor/post/${post.id}`);
|
||||||
|
|
||||||
|
expect(currentURL(), 'currentURL').to.equal(`/editor/post/${post.id}`);
|
||||||
|
|
||||||
|
// Make an edit and save
|
||||||
|
await fillIn('[data-test-editor-title-input]', 'Title 2');
|
||||||
|
await click('[data-test-button="publish-save"]');
|
||||||
|
|
||||||
|
// Check that the unknown card has been removed
|
||||||
|
expect(
|
||||||
|
this.server.db.posts.find(post.id).mobiledoc,
|
||||||
|
'removed unknown card from mobiledoc'
|
||||||
|
).to.deep.equal(JSON.stringify({version: '0.3.1',
|
||||||
|
atoms: [],
|
||||||
|
cards: [],
|
||||||
|
markups: [],
|
||||||
|
sections: [
|
||||||
|
[
|
||||||
|
1,
|
||||||
|
'p',
|
||||||
|
[
|
||||||
|
[
|
||||||
|
0,
|
||||||
|
[],
|
||||||
|
0,
|
||||||
|
'Paragraph 1'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
],
|
||||||
|
ghostVersion: '4.0'}));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user