ckeditor / ckeditor4

The best enterprise-grade WYSIWYG editor. Fully customizable with countless features and plugins.

Home Page:https://ckeditor.com/ckeditor-4

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

specialchar plugin overwrites translation data when opening the dialog causing crash if multiple richtext areas are created after opening the first dialog

nchieffo opened this issue · comments

Type of report

Bug

Provide detailed reproduction steps (if any)

When the user runs the specialchar command, the code executes a call to a function that loads a 2nd localization file in dialogs/lang/ folder.
That file contains a script that executes this function
CKEDITOR.plugins.setLang( 'specialchar', 'en', {

Expected result

The code that is executed in the translation file DOES NOT overwrite the plugin translation data that is stored in CKEDITOR.plugins.registered.specialchar.langEntries

Actual result

The code that is executed in the translation file overwrite the plugin translation data that is stored in CKEDITOR.plugins.registered.specialchar.langEntries

Other details

Normally when using 1 single CKEditor window, the problem is not visible, as the translations are actually extended in the local editor variable, as part of the script load callback.
CKEDITOR.tools.extend( editor.lang.specialchar, plugin.langEntries[ langCode ] );
But at this point the shared translations have been overwritten with the new localization loaded

In the software that I'm using (Coremedia CMS with ckeditor 4.19), multiple CKEditor windows can coexist, and the CKEDITOR variable is shared.
When opening a CMS content with a richtext editor for the first time, and opening the specialchar dialog, everything is fine.
But when opening a second CMS content with a richtext editor, a the CKEDITOR variable is re-used, the plugin is not re-loaded as it's already loaded but it contains the wrong translations, so when the dialog is being created, the lang.title variable is null, causing the plugin to crash.
in specialchar.js

	return {
		title: lang.title,

CKEDITOR crashes because of undefined title variable in the dialog

I have found a way to fix it, by adding an additional invocation in plugin.js

CKEDITOR.scriptLoader.load( CKEDITOR.getUrl( plugin.path + 'dialogs/lang/' + langCode + '.js' ), function() {
	CKEDITOR.tools.extend( editor.lang.specialchar, plugin.langEntries[ langCode ] );
	CKEDITOR.plugins.setLang( 'specialchar', langCode, editor.lang.specialchar); // this is the line I added
	editor.openDialog( pluginName );
} );

It's been a while since we last heard from you. We are marking this issue as stale due to inactivity. Please provide the requested feedback or the issue will be closed after next 7 days.

Why? I was not asked any additional question

@nchieffo, I'd like to apologize for the delay in responding.

Could you show a simple reproduction of the issue, e.g. on CodePen? It would greatly help with debugging the issue.

Sorry but I'm not that experienced with ckeditor, I was just using it through a CMS and I don't know how the instantiations are done.
I will summarize the flow that may be problematic:
STEP 0

  • CKEDITOR variable is initialized

STEP 1

  1. editor widget is loaded in a page div
  2. specialchar plugin is loaded
  3. base specialchar translations are loaded
  4. dialogs/lang/ specialchar translations are loaded
  5. base specialchar translations are lost because the dialogs/lang script invokes CKEDITOR.plugins.setLang( 'specialchar', 'en',

STEP 2

  • another editor widget is loaded in another page div
  • specialchar plugin was already loaded, so it is NOT loaded again
  • at this point the code fails because even if specialchar plugin was already loaded, it misses the default translations that have been overwritten at step 5. before

@nchieffo, I'm not able to reproduce the issue → https://jsfiddle.net/Comandeer/ofw17b3j/

The demo shows two editor instances with specialchar plugin, even with different languages, but everything still works fine.

Thanks for creating the demo, I'll try to have a look and make it reproducible

I started to make some changes, and here's where I was able to do, still incomplete : https://jsfiddle.net/b3d0rezy/2/

The key difference that I'm not able to replicate, is that the plugin is not bundled in the JS, and is not initialized in the config object, but it's initialized afterwards by picking an external .js file called specialchar/plugin.js

CKEDITOR.plugins.addExternal("specialchar", "/resources/com.coremedia.blueprint__vfcorp-studio-plugin/ckeditor/plugins/specialchar/plugin.js", "")

I'm unable to find this file in a public CDN so I can't try to have it in jsfiddle

I've finally managed to reproduce the issue: https://jsfiddle.net/Comandeer/7rhwq8Ld/

Procedure:

  1. Open the "Special Characters" dialog in the first editor.
  2. Close it and press the "CREATE EDITOR 2" button.
  3. Press the "Special Characters" button in the second editor

The actual result:

Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.
    at CKEDITOR.dom.element.append (ckeditor.js:101:300)
    at CKEDITOR.dom.text.appendTo (ckeditor.js:76:77)
    at new CKEDITOR.dialog (ckeditor.js:646:270)
    at a.openDialog (ckeditor.js:689:134)
    at Object.<anonymous> (plugin.js?t=N2M9:36:13)
    at x (ckeditor.js:261:181)
    at y (ckeditor.js:261:336)
    at F (ckeditor.js:261:449)
    at Object.load (ckeditor.js:263:29)
    at CKEDITOR.command.exec (plugin.js?t=N2M9:34:27) 

@Comandeer thank you very much for your help. Do you think that the solution provided in the 1st post may be valid?

Yes, it seems so.