Skip to content

Commit

Permalink
Merge pull request #2762 from blzaugg/2748-Bogus-Element
Browse files Browse the repository at this point in the history
Fixes #2748 Throw friendly error for invalid/missing id's on editor creation
  • Loading branch information
Comandeer authored Feb 6, 2019
2 parents aafb4b1 + 2e8b6b8 commit 003dd66
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
6 changes: 6 additions & 0 deletions core/creators/inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@
if ( !CKEDITOR.env.isCompatible )
return null;

var elementArg = element;

element = CKEDITOR.dom.element.get( element );

// Throw error on missing target element.
if ( !element )
throw 'The provided element, "' + elementArg + '", is missing from the DOM.';

// Avoid multiple inline editor instances on the same element.
if ( element.getEditor() )
throw 'The editor instance "' + element.getEditor().name + '" is already attached to the provided element.';
Expand Down
6 changes: 6 additions & 0 deletions core/creators/themedui.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,14 @@ CKEDITOR.replaceClass = 'ckeditor';
if ( !CKEDITOR.env.isCompatible )
return null;

var elementArg = element;

element = CKEDITOR.dom.element.get( element );

// Throw error on missing target element.
if ( !element )
throw 'The provided element, "' + elementArg + '", is missing from the DOM.';

// Avoid multiple inline editor instances on the same element.
if ( element.getEditor() )
throw 'The editor instance "' + element.getEditor().name + '" is already attached to the provided element.';
Expand Down
50 changes: 50 additions & 0 deletions tests/core/creators/creators.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,31 @@ bender.test( {
wait();
},

'test creator replace on bogus DOM element': function() {
try {
CKEDITOR.replace( 'editorBogus', {
on: {
instanceReady: function() {
resume( function() {
assert.fail( 'Creation should fail on bogus DOM elements.' );
} );
}
}
} );
} catch ( e ) {
resume( function() {
if ( e.toString().indexOf( 'The provided element' ) >= 0 ) {
assert.isTrue( true );
}
else {
assert.fail( 'Error message should be friendly and helpful.' );
}
} );
}

wait();
},

'test creator appendTo': function() {
var tc = this,
container = CKEDITOR.dom.element.createFromHtml( '<div id="foo"></div>' );
Expand Down Expand Up @@ -227,6 +252,31 @@ bender.test( {
wait();
},

'test creator inline on bogus DOM element': function() {
try {
CKEDITOR.inline( 'editorBogus', {
on: {
instanceReady: function() {
resume( function() {
assert.fail( 'Creation should fail on bogus DOM elements.' );
} );
}
}
} );
} catch ( e ) {
resume( function() {
if ( e.toString().indexOf( 'The provided element' ) >= 0 ) {
assert.isTrue( true );
}
else {
assert.fail( 'Error message should be friendly and helpful.' );
}
} );
}

wait();
},

'test creator inline-textarea': function() {
var tc = this,
target = CKEDITOR.document.getBody().append(
Expand Down

0 comments on commit 003dd66

Please sign in to comment.