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

Commit

Permalink
Merge pull request #274 from ckeditor/i/6177
Browse files Browse the repository at this point in the history
Fix: Table border styles conversion handler should not throw when it approaches a nested table. Closes ckeditor/ckeditor5#6177.
  • Loading branch information
mlewand authored Mar 11, 2020
2 parents b53032d + 4de8a27 commit a754898
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
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

0 comments on commit a754898

Please sign in to comment.