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

Commit a754898

Browse files
authored
Merge pull request #274 from ckeditor/i/6177
Fix: Table border styles conversion handler should not throw when it approaches a nested table. Closes ckeditor/ckeditor5#6177.
2 parents b53032d + 4de8a27 commit a754898

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/converters/tableproperties.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ export function upcastBorderStyles( conversion, viewElementName ) {
6060
return;
6161
}
6262

63+
// This can happen when the upcasted table is nested table. As to why it happens, it remains a mystery.
64+
// Take a look at https://github.com/ckeditor/ckeditor5/issues/6177.
65+
if ( !data.modelRange ) {
66+
data = Object.assign( data, conversionApi.convertChildren( data.viewItem, data.modelCursor ) );
67+
}
68+
6369
const modelElement = [ ...data.modelRange.getItems( { shallow: true } ) ].pop();
6470

6571
conversionApi.consumable.consume( data.viewItem, matcherPattern );

tests/tableproperties/tablepropertiesediting.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,24 @@ describe( 'table properties', () => {
210210
assertTRBLAttribute( table, 'borderStyle', null, null, null, 'solid' );
211211
assertTRBLAttribute( table, 'borderWidth', null, null, null, '1px' );
212212
} );
213+
214+
// https://github.com/ckeditor/ckeditor5/issues/6177
215+
it( 'should upcast tables with nested tables in their cells', () => {
216+
editor.setData( '<table style="border:1px solid red">' +
217+
'<tr>' +
218+
'<td>parent:00</td>' +
219+
'<td>' +
220+
'<table style="border:1px solid green"><tr><td>child:00</td></tr></table>' +
221+
'</td>' +
222+
'</tr>' +
223+
'</table>' );
224+
225+
const table = model.document.getRoot().getNodeByPath( [ 0 ] );
226+
227+
assertTRBLAttribute( table, 'borderColor', 'red' );
228+
assertTRBLAttribute( table, 'borderStyle', 'solid' );
229+
assertTRBLAttribute( table, 'borderWidth', '1px' );
230+
} );
213231
} );
214232

215233
describe( 'downcast conversion', () => {

0 commit comments

Comments
 (0)