From e2572c21110a3acce200b7dece07d6093eab014a Mon Sep 17 00:00:00 2001 From: Kamil Piechaczek Date: Mon, 17 Jan 2022 16:11:06 +0100 Subject: [PATCH 1/2] Fixed a crash when removing a content from the last list item next to a non-list element. --- .../src/listpropertiesediting.js | 7 +++ .../tests/listpropertiesediting.js | 57 +++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/packages/ckeditor5-list/src/listpropertiesediting.js b/packages/ckeditor5-list/src/listpropertiesediting.js index 0d52b6006e4..ac991301d55 100644 --- a/packages/ckeditor5-list/src/listpropertiesediting.js +++ b/packages/ckeditor5-list/src/listpropertiesediting.js @@ -214,6 +214,13 @@ export default class ListPropertiesEditing extends Plugin { direction: 'forward' } ); + // If the selection ends in a non-list element, there are no s that would require adjustments. + // See: #8642. + if ( !secondListMostOuterItem ) { + firstMostOuterItem = null; + return; + } + const items = [ secondListMostOuterItem, ...getSiblingNodes( writer.createPositionAt( secondListMostOuterItem, 0 ), 'forward' ) diff --git a/packages/ckeditor5-list/tests/listpropertiesediting.js b/packages/ckeditor5-list/tests/listpropertiesediting.js index 3146cc87d87..6a8654044b7 100644 --- a/packages/ckeditor5-list/tests/listpropertiesediting.js +++ b/packages/ckeditor5-list/tests/listpropertiesediting.js @@ -1530,6 +1530,25 @@ describe( 'ListPropertiesEditing', () => { ); } ); + // See: #8642. + it( 'should not crash when removing entire list item followed by a paragraph element with another list', () => { + setModelData( model, + 'aaaa' + + '[bbbb' + + ']foo' + + 'aaaa' + ); + + editor.execute( 'delete' ); + + expect( getModelData( model ) ).to.equal( + 'aaaa' + + '[]' + + 'foo' + + 'aaaa' + ); + } ); + function simulateTyping( text ) { // While typing, every character is an atomic change. text.split( '' ).forEach( character => { @@ -3198,6 +3217,25 @@ describe( 'ListPropertiesEditing', () => { ); } ); + // See: #8642. + it( 'should not crash when removing entire list item followed by a paragraph element with another list', () => { + setModelData( model, + 'aaaa' + + '[bbbb' + + ']foo' + + 'aaaa' + ); + + editor.execute( 'delete' ); + + expect( getModelData( model ) ).to.equal( + 'aaaa' + + '[]' + + 'foo' + + 'aaaa' + ); + } ); + it( 'should read the `listReversed` attribute from the most outer selected list while removing content between lists', () => { @@ -4828,6 +4866,25 @@ describe( 'ListPropertiesEditing', () => { ); } ); + // See: #8642. + it( 'should not crash when removing entire list item followed by a paragraph element with another list', () => { + setModelData( model, + 'aaaa' + + '[bbbb' + + ']foo' + + 'aaaa' + ); + + editor.execute( 'delete' ); + + expect( getModelData( model ) ).to.equal( + 'aaaa' + + '[]' + + 'foo' + + 'aaaa' + ); + } ); + it( 'should read the `listStart` attribute from the most outer selected list while removing content between lists', () => { From 28d6ff5ea3623d2fe924d49ec09d33435831a2d3 Mon Sep 17 00:00:00 2001 From: Kamil Piechaczek Date: Mon, 17 Jan 2022 16:18:57 +0100 Subject: [PATCH 2/2] Travis, come on.