diff --git a/CHANGES.md b/CHANGES.md index 38a929aed2e..bb7f8442607 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,7 @@ Fixed Issues: * [#13419](http://dev.ckeditor.com/ticket/13419): Fixed: [Auto Link](http://ckeditor.com/addon/autolink) plugin does not encode double quotes in URLs. * [#13460](http://dev.ckeditor.com/ticket/13460): [IE8] Fixed: Copying inline widgets is broken when the Advanced Content Filter is disabled. * [#13495](http://dev.ckeditor.com/ticket/13495): [Firefox,IE] Fixed: Text is not word-wrapped in the Paste dialog. +* [#13385](http://dev.ckeditor.com/ticket/13385): Fixed: [`editor.getSnapshot()`](http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-getSnapshot) may return a non-string value. ## CKEditor 4.5.1 diff --git a/core/editor.js b/core/editor.js index 99770b4a5a8..3b2f1fa3dfe 100644 --- a/core/editor.js +++ b/core/editor.js @@ -904,15 +904,26 @@ * * alert( editor.getSnapshot() ); * - * @see CKEDITOR.editor#getData + * See also: + * + * * {@link CKEDITOR.editor#getData}. + * + * @returns {String} Editor "raw data". */ getSnapshot: function() { var data = this.fire( 'getSnapshot' ); if ( typeof data != 'string' ) { var element = this.element; - if ( element && this.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE ) + + if ( element && this.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE ) { data = element.is( 'textarea' ) ? element.getValue() : element.getHtml(); + } + else { + // If we don't have a proper element, set data to an empty string, + // as this method is expected to return a string. (#13385) + data = ''; + } } return data; diff --git a/tests/core/editor/destroy.js b/tests/core/editor/destroy.js index 1444502c556..abb77e26f03 100644 --- a/tests/core/editor/destroy.js +++ b/tests/core/editor/destroy.js @@ -25,5 +25,16 @@ bender.test( } ); } ); + }, + + // #13385. + 'test getSnapshot returns empty string after editor destroyed': function() { + bender.editorBot.create( {}, function( bot ) { + this.wait( function() { + var editor = bot.editor; + editor.destroy(); + assert.areSame( '', editor.getSnapshot() ); + }, 0 ); + } ); } -} ); \ No newline at end of file +} );