Skip to content
Permalink
Browse files

Merge branch 't/13583'

  • Loading branch information...
Reinmar committed Jul 30, 2015
2 parents 933b853 + 603e15c commit 64385fa67439d2c3d567023ea8b16d83fb150203
Showing with 56 additions and 21 deletions.
  1. +2 −1 CHANGES.md
  2. +17 −9 plugins/clipboard/plugin.js
  3. +37 −11 tests/plugins/clipboard/datatransfer.js
@@ -6,7 +6,8 @@ CKEditor 4 Changelog
Fixed Issues:

* [PR#201](https://github.com/ckeditor/ckeditor-dev/pull/201): Fixed: Buttons in the toolbar configurator cause form submission. Thanks to [colemanw](https://github.com/colemanw)!
* [#13528](http://dev.ckeditor.com/ticket/13528): [Firefox@Windows] Fixed: Content copied from Microsoft Word and other external applications is pasted as plain text. Removed the [`CKEDITOR.plugins.clipboard.isHtmlInExternalDataTransfer`] property as the check must be dynamic.
* [#13528](http://dev.ckeditor.com/ticket/13528): [Firefox@Windows] Fixed: Content copied from Microsoft Word and other external applications is pasted as a plain text. Removed the [`CKEDITOR.plugins.clipboard.isHtmlInExternalDataTransfer`] property as the check must be dynamic.
* [#13583](http://dev.ckeditor.com/ticket/13583): Fixed: [`DataTransfer.getData()`](http://docs.ckeditor.com/#!/api/CKEDITOR.plugins.clipboard.dataTransfer-method-getData) should work consistently on all browsers and not strip valuable content. Fixed pasting tables from Microsoft Excel on Chrome.
* [#13434](http://dev.ckeditor.com/ticket/13434): Fixed: Dialog state indicator broken in Right–To–Left environments.
* [#13451](http://dev.ckeditor.com/ticket/13451): [IE8-9] Fixed: One drag&drop operation may affect following ones.
* [#13129](http://dev.ckeditor.com/ticket/13129) Fixed: Block widget blurred after a drop followed by an undo.
@@ -2059,8 +2059,9 @@
}

this._ = {
chromeLinuxRegExp: /^<meta.*?>/,
chromeWindowsRegExp: /<!--StartFragment-->([\s\S]*)<!--EndFragment-->/,
metaRegExp: /^<meta.*?>/,
bodyRegExp: /<body(?:[\s\S]*?)>([\s\S]*)<\/body>/,
fragmentRegExp: /<!--(?:Start|End)Fragment-->/g,

data: {},
files: [],
@@ -2207,15 +2208,22 @@
data = '';
}

// Chrome add <meta http-equiv="content-type" content="text/html; charset=utf-8">
// at the begging of the HTML data on Linux and surround by <html><body><!--StartFragment-->
// and <!--EndFragment--></body></html> on Windows. This code remove these tags.
if ( type == 'text/html' && CKEDITOR.env.chrome ) {
data = data.replace( this._.chromeLinuxRegExp, '' );
// Some browsers add <meta http-equiv="content-type" content="text/html; charset=utf-8"> at the begging of the HTML data
// or surround it with <html><head>...</head><body>(some content)<!--StartFragment--> and <!--EndFragment-->(some content)</body></html>
// This code removes meta tags and returns only the contents of the <body> element if found. Note that
// some significant content may be placed outside Start/EndFragment comments so it's kept.
//
// See #13583 for more details.
if ( type == 'text/html' ) {
data = data.replace( this._.metaRegExp, '' );

result = this._.chromeWindowsRegExp.exec( data );
if ( result && result.length > 1 ) {
// Keep only contents of the <body> element
result = this._.bodyRegExp.exec( data );
if ( result && result.length ) {
data = result[ 1 ];

// Remove also comments.
data = data.replace( this._.fragmentRegExp, '' );
}
}
// Firefox on Linux put files paths as a text/plain data if there are files
@@ -266,8 +266,8 @@ bender.test( {
assert.areSame( '', dataTransfer.getData( 'cke/undefined' ), 'undefined' );
},

'test getData Chrome Linux fix': function() {
if ( !CKEDITOR.env.chrome ) {
'test getData meta filter': function() {
if ( !CKEDITOR.plugins.clipboard.isCustomDataTypesSupported ) {
assert.ignore();
}

@@ -279,23 +279,49 @@ bender.test( {
assert.areSame( 'foo<b>bom</b>x\nbar', dataTransfer.getData( 'text/html' ) );
},

'test getData Chrome Windows fix': function() {
if ( !CKEDITOR.env.chrome ) {
'test getData body filter': function() {
if ( !CKEDITOR.plugins.clipboard.isCustomDataTypesSupported ) {
assert.ignore();
}

var nativeData = bender.tools.mockNativeDataTransfer();
nativeData.setData( 'text/html',
'<html>\n' +
'<body>\n' +
'<!--StartFragment-->foo<b>bom</b>x\n' +
'bar<!--EndFragment-->\n' +
'</body>\n' +
'</html>\n' );
'<html>' +
'<body foo="bar" bar=foo bom=\'bim\'>' +
'<!--StartFragment-->foo<b>bom</b>x' +
'bar<!--EndFragment-->' +
'</body>' +
'</html>' );

var dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );

assert.areSame( 'foo<b>bom</b>x\nbar', dataTransfer.getData( 'text/html' ) );
assert.areSame( 'foo<b>bom</b>xbar', dataTransfer.getData( 'text/html' ) );
},

'test getData body filter for tables': function() {
if ( !CKEDITOR.plugins.clipboard.isCustomDataTypesSupported ) {
assert.ignore();
}

var nativeData = bender.tools.mockNativeDataTransfer();
nativeData.setData( 'text/html',
'<html>' +
'<body>' +
'<table>' +
'<!--StartFragment-->' +
'<tr><td>foo</td><td>bar</td></tr>' +
'<!--EndFragment-->' +
'</table>' +
'</body>' +
'</html>' );

var dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeData );

assert.areSame(
'<table>' +
'<tr><td>foo</td><td>bar</td></tr>' +
'</table>',
dataTransfer.getData( 'text/html' ) );
},

'test getData Firefox fix': function() {

0 comments on commit 64385fa

Please sign in to comment.
You can’t perform that action at this time.