Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

i/6177: Table border styles conversion handler should not throw when it approaches a nested table #274

Merged
merged 2 commits into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/converters/tableproperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ export function upcastBorderStyles( conversion, viewElementName ) {
return;
}

// This can happen when the upcasted table is nested table. As to why it happens, it remains a mystery.
// Take a look at https://github.com/ckeditor/ckeditor5/issues/6177.
if ( !data.modelRange ) {
data = Object.assign( data, conversionApi.convertChildren( data.viewItem, data.modelCursor ) );
}

const modelElement = [ ...data.modelRange.getItems( { shallow: true } ) ].pop();

conversionApi.consumable.consume( data.viewItem, matcherPattern );
Expand Down
18 changes: 18 additions & 0 deletions tests/tableproperties/tablepropertiesediting.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,24 @@ describe( 'table properties', () => {
assertTRBLAttribute( table, 'borderStyle', null, null, null, 'solid' );
assertTRBLAttribute( table, 'borderWidth', null, null, null, '1px' );
} );

// https://github.com/ckeditor/ckeditor5/issues/6177
it( 'should upcast tables with nested tables in their cells', () => {
editor.setData( '<table style="border:1px solid red">' +
'<tr>' +
'<td>parent:00</td>' +
'<td>' +
'<table style="border:1px solid green"><tr><td>child:00</td></tr></table>' +
'</td>' +
'</tr>' +
'</table>' );

const table = model.document.getRoot().getNodeByPath( [ 0 ] );

assertTRBLAttribute( table, 'borderColor', 'red' );
assertTRBLAttribute( table, 'borderStyle', 'solid' );
assertTRBLAttribute( table, 'borderWidth', '1px' );
} );
} );

describe( 'downcast conversion', () => {
Expand Down