From 738ace4e1837d64874b2dc9d58d3e6afdf7c48d5 Mon Sep 17 00:00:00 2001 From: Szymon Cofalik Date: Tue, 23 Jun 2015 14:21:53 +0200 Subject: [PATCH 1/4] Fixed getSnapshot so it always returns a string. --- core/editor.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/core/editor.js b/core/editor.js index 99770b4a5a8..ee432e6717d 100644 --- a/core/editor.js +++ b/core/editor.js @@ -905,14 +905,22 @@ * alert( editor.getSnapshot() ); * * @see 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; From 3a5729acb202d0ff8567d2a79127f29d2f676143 Mon Sep 17 00:00:00 2001 From: Szymon Cofalik Date: Tue, 23 Jun 2015 14:56:27 +0200 Subject: [PATCH 2/4] Tests for Editor.getSnapshot (when editor destroyed). --- tests/core/editor/destroy.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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 +} ); From 66e7a2cd76d1e8ee147cc6e18abac2bc030a691b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotrek=20Koszuli=C5=84ski?= Date: Wed, 8 Jul 2015 16:39:53 +0200 Subject: [PATCH 3/4] API docs: @see is not supported. --- core/editor.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/editor.js b/core/editor.js index ee432e6717d..3b2f1fa3dfe 100644 --- a/core/editor.js +++ b/core/editor.js @@ -904,7 +904,10 @@ * * alert( editor.getSnapshot() ); * - * @see CKEDITOR.editor#getData + * See also: + * + * * {@link CKEDITOR.editor#getData}. + * * @returns {String} Editor "raw data". */ getSnapshot: function() { From 846ae53143d499219a60049a079e315f789ba7e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotrek=20Koszuli=C5=84ski?= Date: Wed, 8 Jul 2015 16:41:10 +0200 Subject: [PATCH 4/4] Changelog entry. --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) 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