Skip to content

Commit

Permalink
Merge pull request #13859 from ckeditor/ck/13858
Browse files Browse the repository at this point in the history
Fix (list): ListPropertiesEditing should not crash if there was a list in an image caption element. Closes #13858.
  • Loading branch information
arkflpc authored Apr 12, 2023
2 parents 7d5ad28 + 767db45 commit 8162741
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,13 @@ function createAttributeStrategies( enabledProperties: ListPropertiesConfig ) {
function upcastListItemAttributes( attributeStrategies: Array<AttributeStrategy> ) {
return ( dispatcher: UpcastDispatcher ) => {
dispatcher.on<UpcastElementEvent>( 'element:li', ( evt, data, conversionApi ) => {
// https://github.com/ckeditor/ckeditor5/issues/13858
if ( !data.modelRange ) {
return;
}

const listParent = data.viewItem.parent as ViewElement;
const listItem = data.modelRange!.start.nodeAfter || data.modelRange!.end.nodeBefore;
const listItem = data.modelRange.start.nodeAfter || data.modelRange.end.nodeBefore;

for ( const strategy of attributeStrategies ) {
if ( strategy.appliesToListItem( listItem! ) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5405,6 +5405,25 @@ describe( 'ListPropertiesEditing', () => {
'</listItem>'
);
} );

// https://github.com/ckeditor/ckeditor5/issues/13858
it( 'should not convert if the schema does not allow it in the given context', () => {
editor.model.schema.register( 'disallowedContext', {
inheritAllFrom: '$blockObject'
} );

editor.conversion.elementToElement( {
model: 'disallowedContext',
view: {
name: 'div',
classes: 'disallowed-context'
}
} );

editor.setData( '<div class="disallowed-context"><ul><li>foo</li></ul></div>' );

expect( getModelData( editor.model ) ).to.equal( '[<disallowedContext></disallowedContext>]' );
} );
} );
} );

Expand Down

0 comments on commit 8162741

Please sign in to comment.