From 0ac2ed93226b2fdd43d23461486c1bb0873c28aa Mon Sep 17 00:00:00 2001 From: Tomi Blinnikka Date: Thu, 27 Aug 2020 13:56:55 -0500 Subject: [PATCH] Fix #7958 by checking for valid `firstChild`. --- packages/ckeditor5-paste-from-office/src/filters/list.js | 2 +- .../lists/empty-list-item/input.html | 1 + .../lists/empty-list-item/model.html | 1 + .../tests/_data/paste-from-google-docs/lists/index.js | 9 +++++++-- 4 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 packages/ckeditor5-paste-from-office/tests/_data/paste-from-google-docs/lists/empty-list-item/input.html create mode 100644 packages/ckeditor5-paste-from-office/tests/_data/paste-from-google-docs/lists/empty-list-item/model.html diff --git a/packages/ckeditor5-paste-from-office/src/filters/list.js b/packages/ckeditor5-paste-from-office/src/filters/list.js index b17575c697f..e282b8bf469 100644 --- a/packages/ckeditor5-paste-from-office/src/filters/list.js +++ b/packages/ckeditor5-paste-from-office/src/filters/list.js @@ -93,7 +93,7 @@ export function unwrapParagraphInListItem( documentFragment, writer ) { // Google Docs allows on single paragraph inside LI. const firstChild = element.getChild( 0 ); - if ( firstChild.is( 'element', 'p' ) ) { + if ( firstChild && firstChild.is( 'element', 'p' ) ) { writer.unwrapElement( firstChild ); } } diff --git a/packages/ckeditor5-paste-from-office/tests/_data/paste-from-google-docs/lists/empty-list-item/input.html b/packages/ckeditor5-paste-from-office/tests/_data/paste-from-google-docs/lists/empty-list-item/input.html new file mode 100644 index 00000000000..9bcac36d077 --- /dev/null +++ b/packages/ckeditor5-paste-from-office/tests/_data/paste-from-google-docs/lists/empty-list-item/input.html @@ -0,0 +1 @@ + diff --git a/packages/ckeditor5-paste-from-office/tests/_data/paste-from-google-docs/lists/empty-list-item/model.html b/packages/ckeditor5-paste-from-office/tests/_data/paste-from-google-docs/lists/empty-list-item/model.html new file mode 100644 index 00000000000..c1d222b3978 --- /dev/null +++ b/packages/ckeditor5-paste-from-office/tests/_data/paste-from-google-docs/lists/empty-list-item/model.html @@ -0,0 +1 @@ +Item 1 \ No newline at end of file diff --git a/packages/ckeditor5-paste-from-office/tests/_data/paste-from-google-docs/lists/index.js b/packages/ckeditor5-paste-from-office/tests/_data/paste-from-google-docs/lists/index.js index 1e9926b3729..eee01a36938 100644 --- a/packages/ckeditor5-paste-from-office/tests/_data/paste-from-google-docs/lists/index.js +++ b/packages/ckeditor5-paste-from-office/tests/_data/paste-from-google-docs/lists/index.js @@ -15,18 +15,23 @@ import repeatedlyNestedListModel from './repeatedly-nested-list/model.html'; import partiallySelected from './partially-selected/input.html'; import partiallySelectedModel from './partially-selected/model.html'; +import emptyListItem from './empty-list-item/input.html'; +import emptyListItemModel from './empty-list-item/model.html'; + export const fixtures = { input: { nestedOrderedList, mixedList, repeatedlyNestedList, - partiallySelected + partiallySelected, + emptyListItem }, model: { nestedOrderedList: nestedOrderedListModel, mixedList: mixedListModel, repeatedlyNestedList: repeatedlyNestedListModel, - partiallySelected: partiallySelectedModel + partiallySelected: partiallySelectedModel, + emptyListItem: emptyListItemModel } };