Skip to content

Commit

Permalink
Content should be filtered even if config.pasteFilter was not defined…
Browse files Browse the repository at this point in the history
… (because editor.pasteFilter can be created on the fly).
  • Loading branch information
Reinmar committed Mar 16, 2015
1 parent 34667cb commit 7f90ffe
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 23 deletions.
18 changes: 5 additions & 13 deletions plugins/clipboard/plugin.js
Expand Up @@ -126,7 +126,7 @@
}
// On Webkit the pasteFilter defaults 'semantic-content' because pasted data is so terrible
// that it must be filtered.
else if ( CKEDITOR.env.webkit ) {
else if ( CKEDITOR.env.webkit && !( 'pasteFilter' in editor.config ) ) {
filterType = 'semantic-content';
}

Expand Down Expand Up @@ -270,10 +270,9 @@
// Strip presentional markup & unify text markup.
// Forced plain text (dialog or forcePAPT).
if ( type == 'text' && trueType == 'html' ) {
// Init filter only if needed and cache it.
data = filterContent( editor, data, true );
} else if ( !internal && editor.config.pasteFilter ) {
data = filterContent( editor, data );
data = filterContent( editor, data, filtersFactory.get( 'plain-text' ) );
} else if ( !internal && editor.pasteFilter ) {
data = filterContent( editor, data, editor.pasteFilter );
}

if ( dataObj.startsWithEOL ) {
Expand Down Expand Up @@ -1216,14 +1215,7 @@
};
}() );

function filterContent( editor, data, forcedText ) {
var filter = ( forcedText ? filtersFactory.get( 'plain-text' ) : editor.pasteFilter );

// If config.pasteFilter and config.forcePAPT are not defined, then there's no filter.
if ( !filter ) {
return data;
}

function filterContent( editor, data, filter ) {
var fragment = CKEDITOR.htmlParser.fragment.fromHtml( data ),
writer = new CKEDITOR.htmlParser.basicWriter();

Expand Down
16 changes: 12 additions & 4 deletions tests/plugins/clipboard/drop.js
Expand Up @@ -145,29 +145,37 @@ bender.editors = {
name: 'framed',
creator: 'replace',
config: {
allowedContent: true
allowedContent: true,
// Disable pasteFilter on Webkits (pasteFilter defaults semantic-text on Webkits).
pasteFilter: null
}
},
inline: {
name: 'inline',
creator: 'inline',
config: {
allowedContent: true
allowedContent: true,
// Disable pasteFilter on Webkits (pasteFilter defaults semantic-text on Webkits).
pasteFilter: null
}
},
divarea: {
name: 'divarea',
creator: 'replace',
config: {
extraPlugins: 'divarea',
allowedContent: true
allowedContent: true,
// Disable pasteFilter on Webkits (pasteFilter defaults semantic-text on Webkits).
pasteFilter: null
}
},
cross: {
name: 'cross',
creator: 'replace',
config: {
allowedContent: true
allowedContent: true,
// Disable pasteFilter on Webkits (pasteFilter defaults semantic-text on Webkits).
pasteFilter: null
}
}
};
Expand Down
7 changes: 6 additions & 1 deletion tests/plugins/clipboard/paste.js
Expand Up @@ -15,11 +15,16 @@
bender.editor = {
config: {
clipboard_defaultContentType: 'text',
allowedContent: true
allowedContent: true,
// Disable pasteFilter on Webkits (pasteFilter defaults semantic-text on Webkits).
pasteFilter: null
}
};

function testEditor( tc, config, callback ) {
// Disable pasteFilter on Webkits (pasteFilter defaults semantic-text on Webkits).
config.pasteFilter = null;

var editor = new CKEDITOR.editor( config );

editor.on( 'loaded', function() {
Expand Down
34 changes: 34 additions & 0 deletions tests/plugins/clipboard/pastefilter.js
Expand Up @@ -71,6 +71,14 @@
pasteFilter: 'h2',
allowedContent: true
}
},

editorDisabledFilter: {
name: 'editorDisabledFilter',
config: {
allowedContent: true,
pasteFilter: null
}
}
};

Expand Down Expand Up @@ -112,6 +120,15 @@
}
};

tests[ 'editor pasteFilter set to null' ] = function() {
var editor = this.editors.editorDisabledFilter;

assert.isNull( editor.pasteFilter );

assertPasteEvent( editor, { dataValue: '<h2 style="color: red">Foo</h2>' },
{ dataValue: '<h2 style="color: red">Foo</h2>' } );
};

tests[ 'editor has pasteFilter defined if forcePasteAsPlainText is set to true' ] = function() {
var editor = this.editors.editorForcePAPT,
pasteFilter = editor.pasteFilter;
Expand Down Expand Up @@ -156,6 +173,23 @@
{ dataValue: '<p>Foo <strong>bar</strong></p>' }, 'new fitler' );
};

tests[ 'test content is filtered even if config.pasteFilter is undefined' ] = function() {
var editor = this.editors.editorNoConfiguration;

assert.isFalse( !!editor.config.pasteFilter, 'config was not set' );

editor.pasteFilter = new CKEDITOR.filter( 'p h2' );

try {
assertPasteEvent( editor, { dataValue: '<h2>Foo <strong>bar</strong></h2>' },
{ dataValue: '<h2>Foo bar</h2>' }, 'new fitler' );
} catch ( e ) {
throw e;
} finally {
delete editor.pasteFilter; // Tear down properly.
}
};

createTest(
'test plain', 'editorPlain', contents.listWithSpan,
'<p>hefkdjfkdjllo</p><p>moto</p>'
Expand Down
4 changes: 3 additions & 1 deletion tests/plugins/pastefromword/keepstyles.js
Expand Up @@ -8,7 +8,9 @@
bender.editor = {
config: {
pasteFromWordRemoveStyles: false,
pasteFromWordRemoveFontStyles: false
pasteFromWordRemoveFontStyles: false,
// Disable pasteFilter on Webkits (pasteFilter defaults semantic-text on Webkits).
pasteFilter: null
}
};

Expand Down
8 changes: 6 additions & 2 deletions tests/plugins/uploadimage/uploadimage.js
Expand Up @@ -18,15 +18,19 @@
config: {
extraPlugins: 'uploadimage,image',
removePlugins: 'image2',
imageUploadUrl: 'http://foo/upload'
imageUploadUrl: 'http://foo/upload',
// Disable pasteFilter on Webkits (pasteFilter defaults semantic-text on Webkits).
pasteFilter: null
}
},
inline: {
name: 'inline',
creator: 'inline',
config: {
extraPlugins: 'uploadimage,image2',
filebrowserImageUploadUrl: 'http://foo/upload?type=Images'
filebrowserImageUploadUrl: 'http://foo/upload?type=Images',
// Disable pasteFilter on Webkits (pasteFilter defaults semantic-text on Webkits).
pasteFilter: null
}
}
};
Expand Down
4 changes: 3 additions & 1 deletion tests/tickets/11237/1.js
Expand Up @@ -7,7 +7,9 @@

bender.editor = {
config: {
allowedContent: true
allowedContent: true,
// Disable pasteFilter on Webkits (pasteFilter defaults semantic-text on Webkits).
pasteFilter: null
}
};

Expand Down
7 changes: 6 additions & 1 deletion tests/tickets/9456/2.js
Expand Up @@ -5,7 +5,12 @@
( function() {
'use strict';

bender.editor = true;
bender.editor = {
config: {
// Disable pasteFilter on Webkits (pasteFilter defaults semantic-text on Webkits).
pasteFilter: null
}
};

var compat = bender.tools.compatHtml,
engineName = CKEDITOR.env.webkit ? 'webkit' :
Expand Down

0 comments on commit 7f90ffe

Please sign in to comment.