Skip to content

Commit

Permalink
Merge pull request #3641 from ckeditor/t/3586
Browse files Browse the repository at this point in the history
Fix for incorrect recognition of Excel content
  • Loading branch information
f1ames committed Dec 2, 2019
2 parents 6000049 + 630c6c3 commit 2f7937f
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Fixed Issues:
* [#3593](https://github.com/ckeditor/ckeditor4/issues/3593): Fixed: Can't access text or comment node while replacing element node with them via [`CKEDITOR.htmlParser.filter`](https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_htmlParser_filter.html).
* [#3524](https://github.com/ckeditor/ckeditor4/issues/3524): Fixed: [Easy Image](https://ckeditor.com/cke4/addon/easyimage) plugin throws an error when any image with not supported data type is pasted into editor.
* [#3552](https://github.com/ckeditor/ckeditor4/issues/3352): Fixed: Incorrect value of [`CKEDITOR.plugins.widget.repository#selected`](https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_plugins_widget_repository.html#property-selected) after selecting whole editor's content.
* [#3586](https://github.com/ckeditor/ckeditor4/issues/3586): Fixed: Content pasted from Excel is not correctly recognised by [Paste from Word](https://ckeditor.com/cke4/addon/pastefromword) plugin.

## CKEditor 4.13

Expand Down
3 changes: 2 additions & 1 deletion plugins/pastefromword/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@

canHandle: function( evt ) {
var data = evt.data,
mswordHtml = data.dataValue,
// Always get raw clipboard data (#3586).
mswordHtml = CKEDITOR.plugins.pastetools.getClipboardData( data, 'text/html' ),
officeMetaRegexp = /<meta\s*name=(?:\"|\')?generator(?:\"|\')?\s*content=(?:\"|\')?microsoft/gi,
wordRegexp = /(class=\"?Mso|style=(?:\"|\')[^\"]*?\bmso\-|w:WordDocument|<o:\w+>|<\/font>)/,
isOfficeContent = officeMetaRegexp.test( mswordHtml ) || wordRegexp.test( mswordHtml );
Expand Down
Binary file not shown.
11 changes: 11 additions & 0 deletions tests/plugins/pastefromword/manual/preserveexcelstyles.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div id="editor">
<p>Paste things here</p>
</div>

<script>
if ( CKEDITOR.env.safari || ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 ) ) {
bender.ignore();
}

CKEDITOR.replace( 'editor' );
</script>
15 changes: 15 additions & 0 deletions tests/plugins/pastefromword/manual/preserveexcelstyles.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@bender-tags: bug, 4.13.1, 3586
@bender-ui: collapsed
@bender-ckeditor-plugins: wysiwygarea, toolbar, undo, basicstyles, pastefromword, elementspath, tabletools, justify, colorbutton

1. Open [sample Excel file](_assets/3586.xlsx).
1. Copy the blue table.
1. Paste into the editor.

## Expected

Formatting is preserved.

## Unexpected

Formatting (especially background color) is not preserved.
35 changes: 28 additions & 7 deletions tests/plugins/pastefromword/metageneratordetection.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,40 @@

'test generator attribute inside content': function() {
testMetaDetection( this.editor, false, '', '<p name="generator" content="microsoft">Tets</p>' );
},

// (#3586)
'test detection with dataTransfer': function() {
testMetaDetection( this.editor, true, 'Microsoft Excel 16', '<p>Test</p>', {
dataTransfer: true
} );
}
};

ptTools.ignoreTestsOnMobiles( tests );

bender.test( tests );

function testMetaDetection( editor, success, generatorValue, content ) {
function testMetaDetection( editor, success, generatorValue, content, options ) {
var evtData = {
type: 'auto',
dataValue: generateHtml( generatorValue, content ),
method: 'paste'
},
dataType = CKEDITOR.env.ie && CKEDITOR.env.version < 16 ? 'Text' : 'text/html',
isDataTransferTest = options && !!options.dataTransfer,
nativeDataTransfer,
dataTransfer;

if ( isDataTransferTest ) {
nativeDataTransfer = bender.tools.mockNativeDataTransfer();
nativeDataTransfer.setData( dataType, evtData.dataValue );

dataTransfer = new CKEDITOR.plugins.clipboard.dataTransfer( nativeDataTransfer );
evtData.dataValue = dataTransfer.getData( dataType );
evtData.dataTransfer = dataTransfer;
}

editor.once( 'paste', function( evt ) {
resume( function() {
if ( success ) {
Expand All @@ -57,11 +83,7 @@
} );
}, null, null, 999 );

editor.fire( 'paste', {
type: 'auto',
dataValue: generateHtml( generatorValue, content ),
method: 'paste'
} );
editor.fire( 'paste', evtData );

wait();
}
Expand All @@ -70,5 +92,4 @@
var body = content || '<p>foo <strong>bar</strong></p>';
return '<html><head><meta name=Generator content="' + generatorValue + '"></head><body>' + body + '</body></html>';
}

} )();

0 comments on commit 2f7937f

Please sign in to comment.