Skip to content

Commit

Permalink
Merge branch 't/13093' into major
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Jasiun committed Apr 8, 2015
2 parents f7b96c5 + 47d9dd7 commit 0c92f25
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Fixed Issues:
* [#12874](http://dev.ckeditor.com/ticket/12874): Fixed: Information about aggregated tasks should be somehow accessible in [aggregated#finished](http://docs.ckeditor.com/#!/api/CKEDITOR.plugins.notificationAggregator-event-finished).
* [#12503](http://dev.ckeditor.com/ticket/12503): [Blink/Webkit] Fixed: Incorrect result of select all, backspace/delete.
* [#13001](http://dev.ckeditor.com/ticket/13001): [Firefox] Fixed bug with bogus br in the wrong position.
* [#13093](http://dev.ckeditor.com/ticket/13093): [Webkit/Blink] Paste From Word's conflict with the paste filter.

Other Changes:

Expand Down
24 changes: 15 additions & 9 deletions plugins/clipboard/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,14 @@

// Strip presentional markup & unify text markup.
// Forced plain text (dialog or forcePAPT).
// Note: we do not check dontFilter option in this case, because forcePAPT was implemented
// before pasteFilter and pasteFilter is automatically used on Webkit&Blink since 4.5.0, so
// forcePAPT should have priority as it had before 4.5.0.
if ( type == 'text' && trueType == 'html' ) {
data = filterContent( editor, data, filtersFactory.get( 'plain-text' ) );
}
// External paste and pasteFilter exists.
else if ( external && editor.pasteFilter ) {
// External paste and pasteFilter exists and filtering isn't disabled.
else if ( external && editor.pasteFilter && !dataObj.dontFilter ) {
data = filterContent( editor, data, editor.pasteFilter );
}

Expand Down Expand Up @@ -2292,15 +2295,18 @@
* @member CKEDITOR.editor
* @param {CKEDITOR.editor} editor This editor instance.
* @param data
* @param {String} data.type Type of data in `data.dataValue`. Usually `html` or `text`, but for listeners
* with priority less than 6 it may be also `auto`, what means that content type hasn't been recognised yet
* (this will be done by content type sniffer that listens with priority 6).
* @param {String} data.type Type of data in `data.dataValue`. Usually `'html'` or `'text'`, but for listeners
* with priority less than `6` it may be also `'auto'`, what means that content type hasn't been recognised yet
* (this will be done by content type sniffer that listens with priority `6`).
* @param {String} data.dataValue HTML to be pasted.
* @param {String} method Indicates the method of the data transfer. It could be drag and drop or copy and paste.
* Possible values: 'drop', 'paste'.
* @param {CKEDITOR.plugins.clipboard.dataTransfer} dataTransfer Facade for the native dataTransfer object
* @param {String} data.method Indicates the method of the data transfer. It could be drag and drop or copy and paste.
* Possible values: `'drop'`, `'paste'`. Introduced in CKEditor 4.5.0.
* @param {CKEDITOR.plugins.clipboard.dataTransfer} data.dataTransfer Facade for the native dataTransfer object
* which provide access to the various data types, files and pass some date between linked events
* (like drag and drop).
* (like drag and drop). Introduced in CKEditor 4.5.0.
* @param {Boolean} [data.dontFilter=false] Whether the {@link CKEDITOR.editor#pasteFilter paste filter} should not
* be applied to data. This option has no effect when `data.type` equals `'text'`, what means that for instance
* {@link CKEDITOR.config#forcePasteAsPlainText} has a higher priority. Introduced in CKEditor 4.5.0.
*/

/**
Expand Down
3 changes: 3 additions & 0 deletions plugins/pastefromword/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@

// MS-WORD format sniffing.
if ( mswordHtml && ( forceFromWord || ( /(class=\"?Mso|style=\"[^\"]*\bmso\-|w:WordDocument)/ ).test( mswordHtml ) ) ) {
// Do not apply paste filter to data filtered by the Word filter (#13093).
data.dontFilter = true;

// If filter rules aren't loaded then cancel 'paste' event,
// load them and when they'll get loaded fire new paste event
// for which data will be filtered in second execution of
Expand Down
16 changes: 16 additions & 0 deletions tests/plugins/clipboard/pastefilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,22 @@
{ dataValue: '<p>Foo bar</p>' } );
};

tests[ 'evt.data.dontFilter disables paste filter' ] = function() {
var editor = this.editors.editorPlain;

assertPasteEvent( editor, { dataValue: '<h2>Foo <strong>bar</strong></h2>', dontFilter: true },
{ dataValue: '<h2>Foo <strong>bar</strong></h2>', dontFilter: true } );
};

tests[ 'evt.data.dontFilter does not disable the paste filter when forcePAPT is true' ] = function() {
var editor = this.editors.editorForcePAPT;

// Important: forcePAPT is implemented on #beforePaste and the below function does not fire this event.
// Therefore we're passing type:text explicitly.
assertPasteEvent( editor, { dataValue: '<h2>Foo <strong>bar</strong></h2>', dontFilter: true, type: 'text' },
{ dataValue: '<p>Foo bar</p>', dontFilter: true } );
};

createTest(
'test plain', 'editorPlain', contents.listWithSpan,
'<p>hefkdjfkdjllo</p><p>moto</p>'
Expand Down
68 changes: 59 additions & 9 deletions tests/plugins/pastefromword/pastefromword.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,34 @@
( function() {
'use strict';

bender.editor = true;
bender.editors = {
inline: {
creator: 'inline',
name: 'inline'
},

indulgent: {
name: 'indulgent',
config: {
pasteFromWordRemoveFontStyles: false,
pasteFromWordRemoveStyles: false
}
}
};

bender.test( {
'tearDown': function() {
if ( this.editor.showNotification.restore ) {
this.editor.showNotification.restore();
spies: [],

tearDown: function() {
var spy;

while ( spy = this.spies.pop() ) {
spy.restore();
}
},

'test whether default filter is loaded': function() {
var editor = this.editor;
var editor = this.editors.inline;

editor.once( 'paste', function( evt ) {
resume( function() {
Expand All @@ -33,11 +50,44 @@
wait();
},

'test whether paste from word disabled the paste filter': function() {
var editor = this.editors.indulgent,
originalFilter = editor.pasteFilter;

this.spies.push( {
restore: function() {
editor.pasteFilter = originalFilter;
}
} );

// Plug some custom paste filter so on non Webkit/Blink browsers there is some.
editor.pasteFilter = new CKEDITOR.filter( 'p strong' );

editor.once( 'paste', function( evt ) {
resume( function() {
assert.isTrue( evt.data.dontFilter, 'data.dontFilter' );

assert.areSame( '<h1>text</h1><p>text <strong>text</strong></p>',
evt.data.dataValue, 'paste filter was not applied' );
} );
}, null, null, 999 );

editor.fire( 'paste', {
type: 'auto',
// This data will be recognized as pasted from Word.
dataValue: '<h1>text</h1><p>text <strong class="MsoNormal">text</strong></p>',
method: 'paste',
dataTransfer: new CKEDITOR.plugins.clipboard.dataTransfer()
} );

wait();
},

'test paste data structure': function() {
if ( CKEDITOR.env.ie )
assert.ignore();

var editor = this.editor,
var editor = this.editors.inline,
editable = editor.editable();

CKEDITOR.env.ie && editable.once( 'beforepaste', function( evt ) {
Expand Down Expand Up @@ -73,7 +123,7 @@
},

'test showNotification in case of exception': function() {
var editor = this.editor;
var editor = this.editors.inline;

editor.once( 'beforeCleanWord', function( evt ) {
evt.data.filter.addRules( {
Expand All @@ -85,11 +135,11 @@
} );
} );

sinon.stub( editor, 'showNotification', function() {
this.spies.push( sinon.stub( editor, 'showNotification', function() {
resume( function() {
assert.isTrue( true );
} );
} );
} ) );

editor.fire( 'paste', {
type: 'auto',
Expand Down

0 comments on commit 0c92f25

Please sign in to comment.