浏览代码

Merge branch 'master' into i/7704

Aleksander Nowodzinski 5 年之前
父节点
当前提交
7bc707000a

+ 1 - 1
packages/ckeditor5-media-embed/src/automediaembed.js

@@ -16,7 +16,7 @@ import Undo from '@ckeditor/ckeditor5-undo/src/undo';
 import global from '@ckeditor/ckeditor5-utils/src/dom/global';
 import { insertMedia } from './utils';
 
-const URL_REGEXP = /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#[\]@!$&'()*+,;=]+$/;
+const URL_REGEXP = /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#[\]@!$&'()*+,;=%]+$/;
 
 /**
  * The auto-media embed plugin. It recognizes media links in the pasted content and embeds

+ 11 - 0
packages/ckeditor5-media-embed/tests/automediaembed.js

@@ -398,6 +398,17 @@ describe( 'AutoMediaEmbed - integration', () => {
 					return newEditor.destroy();
 				} );
 		} );
+
+		it( 'works for URL with %-symbols', () => {
+			setData( editor.model, '<paragraph>[]</paragraph>' );
+			pasteHtml( editor, 'http://youtube.com/watch?v=H08tGjXNHO4%2' );
+
+			clock.tick( 100 );
+
+			expect( getData( editor.model ) ).to.equal(
+				'[<media url="http://youtube.com/watch?v=H08tGjXNHO4%2"></media>]'
+			);
+		} );
 	} );
 
 	describe( 'use real timers', () => {

+ 14 - 14
packages/ckeditor5-paste-from-office/tests/_data/image/adjacent-groups/model.edge.word2016.html

@@ -2,30 +2,30 @@
 
 <table>
 	<tableRow>
-		<tableCell><paragraph></paragraph></tableCell>
-		<tableCell><paragraph></paragraph></tableCell>
-		<tableCell><paragraph></paragraph></tableCell>
-		<tableCell><paragraph></paragraph></tableCell>
-		<tableCell><paragraph></paragraph></tableCell>
+		<tableCell></tableCell>
+		<tableCell></tableCell>
+		<tableCell></tableCell>
+		<tableCell></tableCell>
+		<tableCell></tableCell>
 	</tableRow>
 	<tableRow>
-		<tableCell><paragraph></paragraph></tableCell>
-		<tableCell colspan="4"><paragraph></paragraph></tableCell>
+		<tableCell></tableCell>
+		<tableCell colspan="4"></tableCell>
 	</tableRow>
 	<tableRow>
-		<tableCell><paragraph></paragraph></tableCell>
+		<tableCell></tableCell>
 	</tableRow>
 	<tableRow>
-		<tableCell><paragraph></paragraph></tableCell>
-		<tableCell colspan="2"><paragraph></paragraph></tableCell>
-		<tableCell rowspan="2"><paragraph></paragraph></tableCell>
+		<tableCell></tableCell>
+		<tableCell colspan="2"></tableCell>
+		<tableCell rowspan="2"></tableCell>
 	</tableRow>
 	<tableRow>
-		<tableCell><paragraph></paragraph></tableCell>
-		<tableCell rowspan="2"><paragraph></paragraph></tableCell>
+		<tableCell></tableCell>
+		<tableCell rowspan="2"></tableCell>
 	</tableRow>
 	<tableRow>
-		<tableCell><paragraph></paragraph></tableCell>
+		<tableCell></tableCell>
 	</tableRow>
 </table>
 

+ 8 - 8
packages/ckeditor5-paste-from-office/tests/_data/image/adjacent-groups/model.safari.word2016.html

@@ -1,20 +1,20 @@
 <paragraph></paragraph>
 <table>
 	<tableRow>
-		<tableCell><paragraph></paragraph></tableCell>
-		<tableCell><paragraph></paragraph></tableCell>
-		<tableCell><paragraph></paragraph></tableCell>
+		<tableCell></tableCell>
+		<tableCell></tableCell>
+		<tableCell></tableCell>
 	</tableRow>
 	<tableRow>
-		<tableCell><paragraph></paragraph></tableCell>
-		<tableCell colspan="2"><paragraph></paragraph></tableCell>
+		<tableCell></tableCell>
+		<tableCell colspan="2"></tableCell>
 	</tableRow>
 	<tableRow>
-		<tableCell><paragraph></paragraph></tableCell>
+		<tableCell></tableCell>
 	</tableRow>
 	<tableRow>
-		<tableCell><paragraph></paragraph></tableCell>
-		<tableCell><paragraph></paragraph></tableCell>
+		<tableCell></tableCell>
+		<tableCell></tableCell>
 	</tableRow>
 </table>
 

+ 14 - 14
packages/ckeditor5-paste-from-office/tests/_data/image/adjacent-groups/model.word2016.html

@@ -1,29 +1,29 @@
 <table>
 	<tableRow>
-		<tableCell><paragraph></paragraph></tableCell>
-		<tableCell><paragraph></paragraph></tableCell>
-		<tableCell><paragraph></paragraph></tableCell>
-		<tableCell><paragraph></paragraph></tableCell>
-		<tableCell><paragraph></paragraph></tableCell>
+		<tableCell></tableCell>
+		<tableCell></tableCell>
+		<tableCell></tableCell>
+		<tableCell></tableCell>
+		<tableCell></tableCell>
 	</tableRow>
 	<tableRow>
-		<tableCell><paragraph></paragraph></tableCell>
-		<tableCell colspan="4"><paragraph></paragraph></tableCell>
+		<tableCell></tableCell>
+		<tableCell colspan="4"></tableCell>
 	</tableRow>
 	<tableRow>
-		<tableCell><paragraph></paragraph></tableCell>
+		<tableCell></tableCell>
 	</tableRow>
 	<tableRow>
-		<tableCell><paragraph></paragraph></tableCell>
-		<tableCell colspan="2"><paragraph></paragraph></tableCell>
-		<tableCell rowspan="2"><paragraph></paragraph></tableCell>
+		<tableCell></tableCell>
+		<tableCell colspan="2"></tableCell>
+		<tableCell rowspan="2"></tableCell>
 	</tableRow>
 	<tableRow>
-		<tableCell><paragraph></paragraph></tableCell>
-		<tableCell rowspan="2"><paragraph></paragraph></tableCell>
+		<tableCell></tableCell>
+		<tableCell rowspan="2"></tableCell>
 	</tableRow>
 	<tableRow>
-		<tableCell><paragraph></paragraph></tableCell>
+		<tableCell></tableCell>
 	</tableRow>
 </table>
 

+ 0 - 25
packages/ckeditor5-table/src/converters/upcasttable.js

@@ -84,31 +84,6 @@ export function skipEmptyTableRow() {
 	};
 }
 
-/**
- * A converter that ensures an empty paragraph is inserted in a table cell if no other content was converted.
- *
- * @returns {Function} Conversion helper.
- */
-export function ensureParagraphInTableCell( elementName ) {
-	return dispatcher => {
-		dispatcher.on( `element:${ elementName }`, ( evt, data, conversionApi ) => {
-			// The default converter will create a model range on converted table cell.
-			if ( !data.modelRange ) {
-				return;
-			}
-
-			const tableCell = data.modelRange.start.nodeAfter;
-
-			// Ensure a paragraph in the model for empty table cells for converted table cells.
-			if ( !tableCell.childCount ) {
-				const modelCursor = conversionApi.writer.createPositionAt( tableCell, 0 );
-
-				conversionApi.writer.insertElement( 'paragraph', modelCursor );
-			}
-		}, { priority: 'low' } );
-	};
-}
-
 // Scans table rows and extracts required metadata from the table:
 //
 // headingRows    - The number of rows that go as table headers.

+ 1 - 3
packages/ckeditor5-table/src/tableediting.js

@@ -9,7 +9,7 @@
 
 import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
 
-import upcastTable, { ensureParagraphInTableCell, skipEmptyTableRow } from './converters/upcasttable';
+import upcastTable, { skipEmptyTableRow } from './converters/upcasttable';
 import {
 	downcastInsertCell,
 	downcastInsertRow,
@@ -106,8 +106,6 @@ export default class TableEditing extends Plugin {
 		// Table cell conversion.
 		conversion.for( 'upcast' ).elementToElement( { model: 'tableCell', view: 'td' } );
 		conversion.for( 'upcast' ).elementToElement( { model: 'tableCell', view: 'th' } );
-		conversion.for( 'upcast' ).add( ensureParagraphInTableCell( 'td' ) );
-		conversion.for( 'upcast' ).add( ensureParagraphInTableCell( 'th' ) );
 
 		conversion.for( 'editingDowncast' ).add( downcastInsertCell() );
 

+ 1 - 1
packages/ckeditor5-table/tests/converters/upcasttable.js

@@ -285,7 +285,7 @@ describe( 'upcastTable()', () => {
 		);
 
 		expectModel(
-			'<fooTable><fooRow><fooCell><paragraph></paragraph></fooCell></fooRow></fooTable>'
+			'<fooTable><fooRow><fooCell></fooCell></fooRow></fooTable>'
 		);
 	} );
 

+ 41 - 0
packages/ckeditor5-table/tests/tableclipboard-paste.js

@@ -3917,6 +3917,36 @@ describe( 'table clipboard', () => {
 				[ '02', '21', '22' ]
 			] ) );
 		} );
+
+		it( 'should not blow up when pasting unsupported element in table', async () => {
+			await createEditor( [ TableCellPropertiesEditing ] );
+
+			pasteHtml( editor,
+				'<table>' +
+					'<tbody>' +
+						'<tr>' +
+							'<td>' +
+								'<div>' +
+									'<table>' +
+										'<tbody>' +
+											'<tr>' +
+												'<td style="border: 2px solid rgb(242, 242, 242);">' +
+													'<p>Test</p>' +
+												'</td>' +
+											'</tr>' +
+										'</tbody>' +
+									'</table>' +
+								'</div>' +
+							'</td>' +
+						'</tr>' +
+					'</tbody>' +
+				'</table>'
+			);
+
+			assertEqualMarkup( getModelData( model, { withoutSelection: true } ), modelTable( [
+				[ '<paragraph>Test</paragraph><paragraph></paragraph>' ]
+			] ) );
+		} );
 	} );
 
 	async function createEditor( extraPlugins = [] ) {
@@ -3930,6 +3960,17 @@ describe( 'table clipboard', () => {
 		tableSelection = editor.plugins.get( 'TableSelection' );
 	}
 
+	function pasteHtml( editor, html ) {
+		const data = {
+			dataTransfer: createDataTransfer(),
+			stopPropagation() {},
+			preventDefault() {}
+		};
+
+		data.dataTransfer.setData( 'text/html', html );
+		editor.editing.view.document.fire( 'paste', data );
+	}
+
 	function pasteTable( tableData, attributes = {} ) {
 		const data = {
 			dataTransfer: createDataTransfer(),