Problem/Motivation

After upgrading from 7.x-1.18 to 7.x-1.19, some configurations in the Custom JavaScript configuration field on CKEditor Profiles cause the editor to fail loading.

Several JavaScript error messages are possible in the console, including:

Uncaught SyntaxError: Unexpected token ; in JSON at position 5
    at JSON.parse (<anonymous>)
    at Object.Drupal.ckeditorInit (ckeditor.utils.js?q7esjx:134)
    at Object.Drupal.ckeditorOn (ckeditor.utils.js?q7esjx:193)
    at HTMLTextAreaElement.<anonymous> (ckeditor.utils.js?q7esjx:319)
    at Function.each (jquery.js?v=1.4.4:34)
    at $.fn.init.each (jquery.js?v=1.4.4:27)
    at attachCKEditor (ckeditor.utils.js?q7esjx:312)
    at Object.attach (ckeditor.utils.js?q7esjx:373)
    at Object.<anonymous> (drupal.js?q7esjx:112)
    at Function.each (jquery.js?v=1.4.4:33)

-- false;CKEDITOR.dtd.$removeEmpty.span = 0

and

ckeditor.utils.js?q7esz7:134 Uncaught TypeError: textarea_settings.js_conf[add_conf].replace is not a function
    at Object.Drupal.ckeditorInit (ckeditor.utils.js?q7esz7:134)
    at Object.Drupal.ckeditorOn (ckeditor.utils.js?q7esz7:193)
    at HTMLTextAreaElement.<anonymous> (ckeditor.utils.js?q7esz7:319)
    at Function.each (jquery.js?v=1.4.4:34)
    at $.fn.init.each (jquery.js?v=1.4.4:27)
    at attachCKEditor (ckeditor.utils.js?q7esz7:312)
    at Object.attach (ckeditor.utils.js?q7esz7:373)
    at Object.<anonymous> (drupal.js?q7esz7:112)
    at Function.each (jquery.js?v=1.4.4:33)
    at Object.Drupal.attachBehaviors (drupal.js?q7esz7:110)
Drupal.ckeditorInit @ ckeditor.utils.js?q7esz7:134
Drupal.ckeditorOn @ ckeditor.utils.js?q7esz7:193
(anonymous) @ ckeditor.utils.js?q7esz7:319
each @ jquery.js?v=1.4.4:34
each @ jquery.js?v=1.4.4:27
attachCKEditor @ ckeditor.utils.js?q7esz7:312
attach @ ckeditor.utils.js?q7esz7:373
(anonymous) @ drupal.js?q7esz7:112
each @ jquery.js?v=1.4.4:33
Drupal.attachBehaviors @ drupal.js?q7esz7:110
(anonymous) @ drupal.js?q7esz7:593
ready @ jquery.js?v=1.4.4:30
u @ jquery.js?v=1.4.4:38

--data = JSON.parse(textarea_settings['js_conf'][add_conf].replace(/'/g, '"'));

Examples of custom configurations that can cause this to break include:

// Single line code comment.
/*
   Multiple-line
   code block comment
*/
config.image2_alignClasses = ['align-left', 'align-center', 'align-right'];
CKEDITOR.dtd.$removeEmpty.span = 0;
config.contentsCss = config.contentsCss.concat( ['my.css'] );
config.extraCss = "body{font-size:15px!important; font-family:-apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',Arial,Helvetica,sans-serif;}";
config.enterMode = CKEDITOR.ENTER_P; 

Proposed resolution

Overhaul the regular expression logic in the js_conf variable processor to strip comments and handle a wider array of potential valid Javascript expressions. In the custom JS-to-PHP interpreter, handle several special cases including booleans and string concatenation operations.

Remaining tasks

  • Write patch.
  • Review patch.
  • Add tests for the regular expression based JS-parser.

User interface changes

None.

API changes

None.

Data model changes

None.

Comments

kruser created an issue. See original summary.

vokiel’s picture

What is your toolbar setting?

Could you set a breakpoint at this line ckeditor.utils.js?q7esz7:134 and dump textarea_settings and add_conf variables?

sbwildflowers’s picture

I'm also seeing this error. My admin config area looks like this:

config.autoParagraph = false;
config.enterMode = CKEDITOR.ENTER_P; 

When I run a dump of textarea_settings['js_conf'][add_conf] wrapped in the same else{} as line 134, I get:
CKEDITOR.ENTER_P

Error appears to be that it's trying to parse a string as json and the else isn't checking that it's an object first. If I remove the parse then that error goes away. Not sure that really fixes the issue as I just get a different JS error farther down the line, and it's hard to tell if it's related.

yntun’s picture

I also encounter the same error. In my case there are some values we commented out in Custom JavaScript configuration under "Edit the CKEditor profile". After I remove those commented lines, it works.

vokiel’s picture

@yntun could you please attach your file, I'm working on the solution and the more use-cases the better.

alex g’s picture

Removing our custom JS config helped.

@vokiel For your reference.

These 2 lines seems to be the culprit in my first use case.

CKEDITOR.dtd.$removeEmpty.i = 0;
CKEDITOR.dtd.$removeEmpty.span = 0;

Doesn't seem to like the ; on the end of these lines.

I've switched to using a custom ckeditor.config.js by enabling the setting for 'Load ckeditor.config.js from the theme path' option.

geophysicist’s picture

There is absolutely different handler to add custom settings. Was:

textarea_settings[add_conf] = eval(textarea_settings['js_conf'][add_conf]);

now:

var data;
if (add_conf == 'toolbar') {
  data = Drupal.ckeditorToolbarToArray(textarea_settings['js_conf'][add_conf]);
} else if (typeof textarea_settings['js_conf'][add_conf] === "boolean" ) {
  data = textarea_settings['js_conf'][add_conf];
} else {
  data = JSON.parse(textarea_settings['js_conf'][add_conf].replace(/'/g, '"'));
}

textarea_settings[add_conf] = data;

In a case in configs you have not just string like in my case:

config.colorButton_colors = 'B3B3B3,' +
'000,800000,8B4513,2F4F4F,008080,000080,4B0082,696969,' +
'B22222,A52A2A,DAA520,006400,40E0D0,0000CD,800080,808080,' +
'F00,FF8C00,FFD700,008000,0FF,00F,EE82EE,A9A9A9,' +
'FFA07A,FFA500,FFFF00,00FF00,AFEEEE,ADD8E6,DDA0DD,D3D3D3,' +
'FFF0F5,FAEBD7,FFFFE0,F0FFF0,F0FFFF,F0F8FF,E6E6FA,FFF';

Replace it to:

config.colorButton_colors = 'B3B3B3,000,800000,8B4513,2F4F4F,008080,000080,4B0082,696969,B22222,A52A2A,DAA520,006400,40E0D0,0000CD,800080,808080,F00,FF8C00,FFD700,008000,0FF,00F,EE82EE,A9A9A9,FFA07A,FFA500,FFFF00,00FF00,AFEEEE,ADD8E6,DDA0DD,D3D3D3,FFF0F5,FAEBD7,FFFFE0,F0FFF0,F0FFFF,F0F8FF,E6E6FA,FFF';

It works in my case.

ezoulou’s picture

+ 1 for comment #4 (remove commented lines in custom config).
Thanks

mpranj’s picture

Comment #4 worked for me as well. Thank you! No idea where the custom config even came from.

vokiel’s picture

Assigned: Unassigned » vokiel
Status: Active » Needs review
StatusFileSize
new2.88 KB

Attaching patch, which should solve problems mentioned here for:

- #3 @danoftheclanmcleod with CKEDITOR.ENTER_P
- #6 @Alex G with custom code not being config. option (such code will be removed and should be added different way).
- #7 @geophysicist with concatenated JavaScript string.

Can I ask you to test the patch in your (original) settings?

geophysicist’s picture

@vokiel, looks like it works for me. #10 patch is applied and configs reverted back

flotsam’s picture

I get the same / similar error as the OP after update to ckeditor-7.x-1.19 from .18 . There are no special configurations on the site in question - it's a vanilla install of CKEditor in Drupal 7.69

jquery-1.10.2.min.js:6 Uncaught TypeError: textarea_settings.js_conf[add_conf].replace is not a function
    at Object.Drupal.ckeditorInit (ckeditor.utils.js?q7g7fs:134)
    at Object.success (ckeditor.utils.js?q7g7fs:188)
    at c (jquery-1.10.2.min.js:4)
    at Object.fireWith [as resolveWith] (jquery-1.10.2.min.js:4)
    at k (jquery-1.10.2.min.js:6)
    at r (jquery-1.10.2.min.js:6)
    at Object.send (jquery-1.10.2.min.js:6)
    at Function.ajax (jquery-1.10.2.min.js:6)
    at Object.Drupal.ckeditorOn (ckeditor.utils.js?q7g7fs:177)
    at HTMLTextAreaElement.<anonymous> (ckeditor.utils.js?q7g7fs:319)

Patch from #10 did not change the error, and CKEditor does not load.

tmin’s picture

Status: Needs review » Reviewed & tested by the community

@vokiel :

Had the exact same issue that the other users mentioned.

The patch seems to be working for me too.

Since this seems like an obvious regression and the changes that have been made seem sensible to me, I'm marking the issue as "reviewed and tested by the community" in order to be applied to the module as soon as possible.

sbwildflowers’s picture

@vokiel, patch applied and works to clear up the original error.

I still get another error down the line from the library itself (4.14), but it's not clearly related in any way. This error occurs regardless of whether there is custom js configs present or not, so likely out of the scope of this issue. But in-case anyone else gets the same thing:

ckeditor.js?q7ga8c:544 Uncaught TypeError: Cannot read property 'split' of undefined
    at Object.loadPart (ckeditor.js?q7ga8c:544)
    at l (ckeditor.js?q7ga8c:283)
    at a.<anonymous> (ckeditor.js?q7ga8c:282)
    at a.l (ckeditor.js?q7ga8c:10)
    at a.<anonymous> (ckeditor.js?q7ga8c:12)
    at a.CKEDITOR.editor.CKEDITOR.editor.fire (ckeditor.js?q7ga8c:13)
    at a.fireOnce (ckeditor.js?q7ga8c:12)
    at a.CKEDITOR.editor.CKEDITOR.editor.fireOnce (ckeditor.js?q7ga8c:13)
    at k (ckeditor.js?q7ga8c:280)
    at Object.<anonymous> (ckeditor.js?q7ga8c:280)
caspervoogt’s picture

had same issue, #10 fixed the 'Uncaught SyntaxError: ' error for me. On one site, though, I also had the "textarea_settings.js_conf[add_conf].replace is not a function" error, and the #10 patch did not solve that one for me in that case. I have no custom JS / config.js in place so that is a non-issue in my case.

Reverting to 1.18 worked for now, but obviously I will need to update to 1.19 ASAP. I just can't... it makes the editor unusable.

bazzmann’s picture

Hi there,
we are encountering same problems right here.

The optional parameter inserted on the textarea of the module now don't work anymore, since the last update. Both using:

config.font_names = 'apple-system;BlinkMacSystemFont;Segoe UI;Roboto;Oxygen;Ubuntu;Cantarell;Fira Sans;Droid Sans;Helvetica Neue;Arial;Helvetica;sans-serif;';
config.fontSize_sizes = '15/15px;';
config.scayt_sLang = 'it_IT';

or

config.extraCss = "body{font-size:15px!important; font-family:-apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',Arial,Helvetica,sans-serif;}";

And, for what we can see at now, also trying to put the config.js file on the theme folder. Simply don't work. No optional parameter seems to be loaded by the CKEditor.

Any idea?

vokiel’s picture

@bazzmann have you tried with the patch? I just check your config and it seems to be working fine with the patch.

kaosagnt’s picture

Patch 3120705-10.patch contains logic error that causes issues with custom Javascript.

- data = JSON.parse(textarea_settings['js_conf'][add_conf].replace(/'/g, '"'));
+ item = textarea_settings['js_conf'][add_conf].replace(/'/g, '"');
+ if (item.indexOf('CKEDITOR.') > -1 && item === item.toUpperCase()) { /* CKEDITOR constant */
+ data = CKEDITOR[item.replace('CKEDITOR.', '')] || null;
+ } else if (item.indexOf('\'') > -1 || item.indexOf('"') > -1) { /* Found JSON string */
+ data = JSON.parse(item);
+ } else { /* Custom JS */
+ data = (new Function('"use strict"; return '+item)());
+ }

Replacing all ' chars with " via replace(/'/g, '"');

test for both ' || " causes a call to JSON.parse(Item) instead of else { */ Custom JS

Removing the || item.indexOf('"') > -1 test makes the CKeditor load with and ADVANCED Option - Custom Javascript Configuration.

Still testing ATM.

RaySilver’s picture

Same problem here as others after updating getting JS error " SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data at line 1 column 50 of the JSON data "

Don't have anything fancy in CKE.. all default settings.. went to Advanced Settings and saw this in there "didn't even know it was there before"

config.allowedContent = true;
config.extraAllowedContent = 'p(*)[*]{*};div(*)[*]{*};li(*)[*]{*};ul(*)[*]{*}';
CKEDITOR.dtd.$removeEmpty.i = 0;

Deleted it.. and now it's loading. But not sure now if it's going to have some impact somewhere?

yntun’s picture

@vokiel the lines I commented out are sth like
//config.baseHref = 'http://local.demo:8082/';
//config.templates = 'templatename';

I also tested the patch. It does not work yet for commented lines, the same error thrown.

ctrnz’s picture

Also got
textarea_settings.js_conf[add_conf].replace is not a function
Changing textarea_settings['js_conf'][add_conf].replace(/'/g, '"'); to
textarea_settings['js_conf'][add_conf].toString().replace(/'/g, '"'); seems to fix an issue.
Still testing rest of functionalities.

vokiel’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new3.33 KB

I'm attaching a new patch which fixes some mentioned issues.

It also stripes all comments and removes non-config lines.

Please test it in your configurations.

sthomen’s picture

#22 seems to have fixed the problem with textarea_settings.js_conf[add_conf].replace is not a function for me. Thank you.

marcopbazz’s picture

Tryed both #10 and #22 and I get the same results as @Bazzmann.

What I've noticed is different results with the optional parameter, if I use:

config.font_names = 'apple-system;BlinkMacSystemFont;Segoe UI;Roboto;Oxygen;Ubuntu;Cantarell;Fira Sans;Droid Sans;Helvetica Neue;Arial;Helvetica;sans-serif;';
config.fontSize_sizes = '15/15px;';
config.scayt_sLang = 'it_IT';

Editor appear, but optional parameter aren't loaded.

If I use
config.extraCss = "body{font-size:15px!important; font-family:-apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',Arial,Helvetica,sans-serif;}";

Ckeditor doesn't appear at all

giuvax’s picture

Same here. On one of my website CK Editor won't load. I get this.

Uncaught TypeError: textarea_settings.js_conf[add_conf].replace is not a function
    at Object.Drupal.ckeditorInit (js_vA50U8AaB0c8ojxE-8MHzcXtUzLkCqWpqWQe5Ec8kCo.js:134)
    at Object.Drupal.ckeditorOn (js_vA50U8AaB0c8ojxE-8MHzcXtUzLkCqWpqWQe5Ec8kCo.js:193)
    at HTMLTextAreaElement.<anonymous> (js_vA50U8AaB0c8ojxE-8MHzcXtUzLkCqWpqWQe5Ec8kCo.js:319)
    at Function.each (js_DleaAAlxlaDoO0HnVj1Faq2J3lCtl-mwLzKDo0aUj-c.js:2)
    at m.fn.init.each (js_DleaAAlxlaDoO0HnVj1Faq2J3lCtl-mwLzKDo0aUj-c.js:2)
    at attachCKEditor (js_vA50U8AaB0c8ojxE-8MHzcXtUzLkCqWpqWQe5Ec8kCo.js:312)
    at Object.attach (js_vA50U8AaB0c8ojxE-8MHzcXtUzLkCqWpqWQe5Ec8kCo.js:373)
    at Object.<anonymous> (js_xcuyIw2ON5hlpRPxtZOtT3XQ16Nontd1xew5uUFTe9A.js:305)
    at Function.each (jquery-2.2.4.min.js:2)
    at Object.Drupal.attachBehaviors (js_xcuyIw2ON5hlpRPxtZOtT3XQ16Nontd1xew5uUFTe9A.js:303)
giuvax’s picture

I just use the patch for ckeditor.utils.js and it loaded. Should I edit the other file too?

flotsam’s picture

Using the patch from #22 fixed this for me - thanks much @vokiel!

@giuvax - I believe you only need to use the patch from #22 (if you try to load both, one of the patches will be rejected).

bazzmann’s picture

@vokiel, as @marcopbazz told, there is no resolution using one of the patch here present.

No one optional parameter seems to be working.

caspervoogt’s picture

the patch from #22 solved the "replace" JS error for me

kruser’s picture

Patch #22 fixed all my sites! thanks.

vokiel’s picture

StatusFileSize
new9.66 KB

Huge update.

I've reviewed most of the possible configuration options. Except for a couple of not that common (or rather harder to implement ;-) ), all should work.

Also, added support for custom CKEDITOR.dtd so you can keep it.

Please all involved try the newest patch with your original configurations.

vokiel’s picture

marcopbazz’s picture

Patch #31 worked for me!

mchaplin’s picture

When's the release that contains #31 patch?

vokiel’s picture

@mchaplin this week for sure, just want to gather more feedback.

jrearick’s picture

I tested #31 and seems to work nicely! Patch applied to 7.x-1.x-dev. I can't wait for the release.

We had the following in our custom JS configuration in the UI:

CKEDITOR.config.specialChars = CKEDITOR.config.specialChars.concat( [[ ‘&alpha;', 'Greek small letter alpha' ], [ ‘&beta;', 'Greek small letter beta' ]] );

With the following error on unpatched:

Uncaught SyntaxError: Unexpected token C in JSON at position 0
    at JSON.parse (<anonymous>)
    at Object.Drupal.ckeditorInit (ckeditor.utils.js?q7er6n:134)
    at Object.Drupal.ckeditorOn (ckeditor.utils.js?q7er6n:193)
    at HTMLTextAreaElement.<anonymous> (ckeditor.utils.js?q7er6n:319)
    at Function.each (jquery.js?v=1.4.4:34)
    at $.fn.init.each (jquery.js?v=1.4.4:27)
    at attachCKEditor (ckeditor.utils.js?q7er6n:312)
    at Object.attach (ckeditor.utils.js?q7er6n:373)
    at Object.<anonymous> (drupal.js?q7er6n:112)
    at Function.each (jquery.js?v=1.4.4:33)

I'll defer to your judgement for marking this RTBC. Thanks @vokiel for taking this on!

kualee’s picture

I have tested out the patch in #31 applied to 7.x-1.x-dev on a vanilla drupal site, and also another 10 of our sites and they are working as intended
The extra custom JS config in our environments are

config.allowedContent = true;
config.extraAllowedContent = 'p(*)[*]{*};div(*)[*]{*};li(*)[*]{*};ul(*)[*]{*}';
CKEDITOR.dtd.$removeEmpty.i = 0;

I had similar error message as in the original issue summary before applying the patch
Uncaught SyntaxError: Unexpected token ; in JSON at position 5

yntun’s picture

@vokiel I tested patch #31, it works for config with commented lines, js error is removed. But it wipes out other icons (such as B, I, U) and custom styles we added (Styles dropdown disabled). After I reverse the patch, it works as per normal. So I would say it is not working for our site.

vokiel’s picture

@jrearick you don't need to use full CKEDITOR.config chain, as config is parsed withing the CKEDITOR object available.

Instead
CKEDITOR.config.specialChars = CKEDITOR.config.specialChars.concat( [[ ‘&alpha;', 'Greek small letter alpha' ], [ ‘&beta;', 'Greek small letter beta' ]] );

just use this:
config.specialChars = config.specialChars.concat( [[ "&alpha;", "Greek small letter alpha" ], [ "&beta;", "Greek small letter beta" ]] );

@yntun can you paste here your config so I can debug it?

aidas85’s picture

Hi,

I'm still getting an error on the following custom JS config:

CKEDITOR.config.contentsCss = [CKEDITOR.config.contentsCss, 'my.css'];

Using 7.x-1.x branch.

Error:

jquery.min.js?v=1.7.2:4 Uncaught SyntaxError: Unexpected token C in JSON at position 1
    at JSON.parse (<anonymous>)
    at Object.Drupal.ckeditorInit (ckeditor.utils.js?q7rbad:134)
    at Object.success (ckeditor.utils.js?q7rbad:188)
    at o (jquery.min.js?v=1.7.2:2)
    at Object.fireWith [as resolveWith] (jquery.min.js?v=1.7.2:2)
    at w (jquery.min.js?v=1.7.2:4)
    at d (jquery.min.js?v=1.7.2:4)
    at Object.send (jquery.min.js?v=1.7.2:4)
    at Function.ajax (jquery.min.js?v=1.7.2:4)
    at Object.Drupal.ckeditorOn (ckeditor.utils.js?q7rbad:177)
vokiel’s picture

@aidas85 look at my post #39.

instead of
CKEDITOR.config.contentsCss = [CKEDITOR.config.contentsCss, 'my.css'];

use
config.contentsCss = config.contentsCss.concat( ['my.css'] );

vokiel’s picture

StatusFileSize
new9.88 KB

An updated patch that fixes configuration which uses pre-defined values like in @aidas85 is ready.

instead of
CKEDITOR.config.contentsCss = [CKEDITOR.config.contentsCss, 'my.css'];

please use build-in concat() method:
config.contentsCss = config.contentsCss.concat( ['my.css'] );

It can be used for other Array based settings, like:
config.specialChars = config.specialChars.concat( [ '&quot;', [ '&rsquo;', 'Custom label' ] ] );

javmorais’s picture

Hi,

I have a problem applying the patches #31 and #42 because my original ckeditor 7.x-1.19 module file "/includes/ckeditor.lib.inc" has diferent content than the patch expected.

Code of patch:

@@ -179,7 +179,7 @@ function ckeditor_load_skin_options() {
   }
 
   // If we have no information about skins, use the default for this version.
-  if (empty($arr)) {
+  if (!$arr) {
     $arr = array(
       'moono-lisa' => 'Moono-lisa',
       'moono' => 'Moono',
@@ -607,8 +607,8 @@ function ckeditor_profile_settings_compile($global_profile, $profile) {
   $settings['width'] = $conf['width'];
   //check if skin exists, if not select default one
   if (isset($global_profile->settings['skin']) && file_exists($editor_local_path . '/skins/' . $global_profile->settings['skin']) ||
-      isset($global_profile->settings['skin']) && $editor_local_path == '<URL>'
-    ) {
+    isset($global_profile->settings['skin']) && $editor_local_path == '<URL>'
+  ) {
     $settings['skin'] = $global_profile->settings['skin'];
   }
   else {

Code of "/includes/ckeditor.lib.inc" file:
lines 179 to 186

  }

  // If we have no information about skins, use the default for this version.
  if (!$arr) {
    $version = explode('.', ckeditor_get_version());
    if ($version[0] == 3) {
      $arr = array('kama' => 'Kama');
    }

lines 607 to 615

if ($conf['expand'] == 'f') {
    $settings['toolbarCanCollapse'] = true;
  }
  $settings['width'] = $conf['width'];
  //check if skin exists, if not select default one
  if (isset($global_profile->settings['skin']) && file_exists($editor_local_path . '/skins/' . $global_profile->settings['skin'])) {
    $settings['skin'] = $global_profile->settings['skin'];
  }
  else {

I can apply the patch and I have no JavaScript error and I can use ckeditor editing and creatting my pages. But I don´t know if I must to do by my self the changes the patch can't do to my file.

Can you help me?

Thanks

Regards

Javi

vokiel’s picture

@javmorais I'm sorry, I generated the patch from current dev instead of last release. The new patch should be fine now.

javmorais’s picture

@vokiel thanks for your response!!

I can't see the new patch. Do you mean you will generate it?

Regards

Javi

vokiel’s picture

StatusFileSize
new9.07 KB
gyogyika’s picture

Patch #46 worked for me!

javmorais’s picture

Hi,

Patch #46 works. But it wipes out other icons (such as B, I, U) in "full html" profile. If I config the "Filter HTML" profile to show all buttons it works.

Can you help me more?

Thanks!!

Regards

Javi

insanityinside’s picture

I'm also seeing this issue, even with the patch, error was the Uncaught TypeError: textarea_settings.js_conf[add_conf].replace is not a function. No custom options present as far as I can see, but it's trying to do the regex replace on a number.

textarea_settings['js_conf']:
{filebrowserWindowWidth: 700, filebrowserWindowHeight: 400}
add_conf:
"filebrowserWindowWidth"
textarea_settings['js_conf'][add_conf]:
700

The toString method above by @ctrnz solves the issue.

mario steinitz’s picture

After updating a Drupal 7 site of our clients to most recent released Core and contributed modules, we faced the same issue as described here.
The patch from #47 fixed the issue using the current release of the ckeditor module.

We previously removed all comments from all custom ckeditor settings as suggested in #4, which did not help.

The custom configuration used was something like this:

CKEDITOR.stylesSet.add('my-styles', [
  {name : 'Blue Title', element : 'h2', styles : {'color' : 'Blue' }},
  {name : 'Red Title' , element : 'h3', styles : {'color' : 'Red' }},
  {name : 'CSS Style', element : 'span', attributes : {'class' : 'my-style' }},
  {name : 'Marker: Yellow', element : 'span', styles : {'background-color' : 'Yellow'}}
]);
javmorais’s picture

Hi,

@vokiel I have solved my problem described in #48 just removing any changes in includes/ckeditor.lib.inc made by the last patch (44).

Do you think it can generate any other problems? I think do what I say is OK just depending on the module configuration. I don't know if reverting the changes in that file can generate security issues.

What do you think?

Thanks.

Regards

Javi

freddyedu’s picture

Status: Needs review » Needs work

Hi,

Similarly to the problem described in #48, I am also missing Toolbar options that were set by my Editor Profile before updating the module and then applying Patch #46. More specifically, It appears that my configured Editor Profile is being ignored altogether. I Say this because the Toolbar Options that are missing after updating the module and applying the patch come back after reverting to the previously installed version of the module (7.x-1.18). Patch #46 was the one-and-only patch that I tried, so there were no other patch changes to clean up.

kualee’s picture

I have just retested patch in #46 with 7.x-1.19 (I tested the 7.x-1.x-dev in #37 and didn't have any issue),and similar to #48 and #52, all the extra buttons were removed, I have tried saving, reconfig, flush caches multiple times etc to no availability

thatguy’s picture

I updated from 7.x-1.18+4-dev to 7.x-1.19 and used patch from #46 to fix the JS error but I have the same issue of losing some buttons that were previously there, for example bold, italic, underline. For me the issue seems to be 'config.allowedContent = true;' that has been set in 'Custom JavaScript configuration' -field in the CKEditor profile. If I remove that line, the editor works correctly again and the buttons show correctly. Is the option maybe not supported anymore?

aidas85’s picture

Using 1.19 version + parsing_custom_js-3120705-44.patch, I'm also unable to display any custom buttons. We have 4 custom plugins, all written in JS, with custom icons to go into the toolbar. In the CMS page where the editor is used, I can see the plugin JS files being loaded fine, with no errors, however the buttons won't show. Re-adding them through the configuration page, unfortunately does not solve the issue.

javmorais’s picture

Hi,

Testing by my self in different sites, I think there are two solutions after updating ckeditor module to 7.x-1.19, updating library to 4.14.0 and applying patch #46, if it wipes out icons (such as B, I, U):

  1. Delete your Custom JavaScript configuration in file (ckeditor.config.js) or admin/config/content/ckeditor/edit/Full (Advanced Options)
  2. Or if you need that custom configuration, you can remove any changes in includes/ckeditor.lib.inc made by the last patch

But I don't know if option 2 has any security issue. I'm waiting for someone to answer #51

Regards

Javi

teebo’s picture

Personally, #6 temporarily fixes the issue:

I've switched to using a custom ckeditor.config.js by enabling the setting for 'Load ckeditor.config.js from the theme path' option.

Enabling empty (i or span) tags was also my issue.

CKEDITOR.dtd.$removeEmpty.i = 0;
CKEDITOR.dtd.$removeEmpty.span = 0;

All other configs starting with config.xxx were accepted.

aiglesiasn’s picture

Hi!

I used patch #46, and my site works again properly.

Thank you very much for the update!

Andrés

candelas’s picture

Thanks @vokiel patch #46 worked perfect

subham1707’s picture

Hi,

It worked for me too.

Thanks,

vokiel’s picture

@Mario Steinitz predefined styles should be added to ckeditor.styles.js and set in panel in CSS section.

@javmorais, @freddyedu what are your full profile configurations? Maybe icons were not added in the panel (in the Editor appearance section) or in the custom config? What are your settings for AllowedContent? I was checking the default setup and those icons are displayed for me.

@kualee how were your extra buttons added to the editor, can you please share the configuration?

@Teebo have you tried the newest patch with your dtd settings. They should work now.

The config.AllowedContent can be set in Allowed content filter administration panel section. No need to add this to custom JavaScript.

javmorais’s picture

Hi @vokiel,

Thanks for your response.

My problem is only when I have Custom JavaScript configuration. This is my custom JavaScript configuration:

config.allowedContent = true;
config.extraAllowedContent = 'a span';
CKEDITOR.dtd.$removeEmpty.span = 0;

If I delete the last "CKEDITOR.dtd.$removeEmpty.span = 0;", evrything works properly and I don´t need to apply the patch.

Thanks!!!!

Regards.

Javi

Sylense’s picture

The latest update also broke all of my ckeditor profiles as mentioned here. I use many different profiles with their own sets of custom configuration files but the 2nd suggestion presented by javmorais in #56 fixed my issue. Any security repercussions? I'm wondering how/why this was cleared as a stable release if it clearly affects many sites and there's no mention of it on the module page.

javmorais’s picture

Hi,

@Sylense, had you tried my last suggestion in #62? My problem only was the last line in my custom JavaScript configuration

Regards,

Javi.

mchaplin’s picture

Hi @vokiel what's the latest on a release for this issue?

Thanks Mike

Sylense’s picture

@javmorais, I'm not using any dtd declarations in any of my profiles. After my last comment I noticed that the Token plugin I'm using for ckeditor was broken. The token definitions in the dropdowns had weird parsing that I believe was caused by changes in ckeditor.utils.js. I don't have time right now to debug what caused it so for now using the latest 7x dev (4/19/20) but overwriting ckeditor.utils.js from 7.x-1.18 works. This is obviously not optimal but I need this working on my production site for the time being until a permanent fix is found. Thanks for all the dialogue and work thus far.

javmorais’s picture

Hi,

@Sylense, be carefoul using a file from a prevous release. I recomend you to check the differences between 7.x-1.18 and 7.x-1.19 in that file. Maybe there are any changes related with the security issue.

I didn't have any problem with the token or ckeditor.utils.js file.

Regards,

Javi

vokiel’s picture

StatusFileSize
new8.94 KB

Attaching a new patch (based on current development branch: 7.x-1.x), where issues with empty toolbar are fixed.

Two notes:
1. Some of you wonder what changed so much in the last release and why.
The main change was the removal of eval() usage (on custom JS). It was due to security concerns. Eval can be handy as it allows custom JS, even not connected with CKEditor settings at all. On the other hand - it allowed any custom JS ;-) which could be either a security issue or could bring a bit of mess. Other than that, eval() was blocking more strict CSP rules to be applied.

2. The new version is trying to parse custom JS and find there configuration options that can be applied to the Editor. Not all possible cases were addressed thus so many issues.

I've tested all custom configuration posted in this thread and all of them seem to be working fine. Of course, some of them needed small change, e.g:

instead of:
CKEDITOR.config.contentsCss = [CKEDITOR.config.contentsCss, 'my.css'];
use
config.contentsCss = config.contentsCss.concat( ['my.css'] );

The CKEDITOR namespace should be used only for the CKEDITOR.dtd which is not a config option, but used here quite often so it got custom processing. Others should be simplified to use just the config. part.

Also, all custom code not being an Editor settings option should go to custom JS.

Please verify the patch and if no new issues will be found I'll be releasing a new version shortly.

Thank you all for your support, testing and comments.

jrearick’s picture

Huh, I had a hunch that was the point of all the regex processing of the configuration :)

I'm sure there's plenty of people who have custom code in the configuration field. I don't think it's possible to account for all of those cases, but it sounds like a fair security consideration. Stuff that is not configuration probably *should* be in a custom plugin.

The patch in #68 seems to have not broken for me with the following configurations:

config.specialChars = config.specialChars.concat( [[ '&alpha;', 'Greek small letter alpha' ], [ '&beta;', 'Greek small letter beta' ]] );

Even with the CKEDITOR. prefix, it still worked...
CKEDITOR.config.specialChars = CKEDITOR.config.specialChars.concat( [[ '&alpha;', 'Greek small letter alpha' ], [ '&beta;', 'Greek small letter beta' ]] );

And the CKEDITOR.dtd seems to have worked:

config.allowedContent = true;
config.extraAllowedContent = 'a span';
CKEDITOR.dtd.$removeEmpty.span = 0;

FWIW, I approve.

Hopefully, @javmorais can test this patch as well.

jrearick’s picture

Status: Needs work » Needs review
theorichel’s picture

Had the same problem with v 1.19 and removing the customization of my Config file did the trick. Thanks Vokiel!

jrearick’s picture

Status: Needs review » Reviewed & tested by the community

There doesn't seem to be any movement on reviewing this. I assume the patch in #68 works for everyone? It worked fine for me almost two weeks ago. I'm setting status to RTBC in hopes of advancing a release.

mchaplin’s picture

For at least one site, all I had to do was remove the final ; from the last line in the format Custom JavaScript configuration eg

admin/config/content/ckeditor/edit/Full

config.allowedContent = true;
config.extraAllowedContent = 'p(*)[*]{*};div(*)[*]{*};li(*)[*]{*};ul(*)[*]{*}';
CKEDITOR.dtd.$removeEmpty.i = 0;

becomes

config.allowedContent = true;
config.extraAllowedContent = 'p(*)[*]{*};div(*)[*]{*};li(*)[*]{*};ul(*)[*]{*}';
CKEDITOR.dtd.$removeEmpty.i = 0

jrearick’s picture

@mchaplin, when I remove the semicolon from the configuration using the unpatched 7.x-1.19 module, it disables the configuration, but the buttons do return. Have you confirmed that your configuration is still working as expected?

A workaround I found is to create a custom CKEditor plugin with the custom configuration in the init. Something like

CKEDITOR.plugins.add( 'myplugin', {
    init: function( editor )
    {
      editor.config.hideDialogFields="image:info:txtUrl";
    }
  });

We have a platform that often contains custom configuration in the UI, so manually creating a plugin for each site is not going to work for us. We'll be deploying the patch in #68.

zorax’s picture

I confirm #73 save my night...
Thanks mchaplin !

oranges13’s picture

Updating to 1.19 with this custom config broke everything -- how can I modify it to work with the updated version?

config.templates_files = [ Drupal.settings.basePath + 'sites/all/themes/my_theme/ckeditor/ckeditor.custom.templates.js' ];

In our case we're adding custom templates from our theme for use in the editor.

mile23’s picture

+1 on RTBC in spirit. This JS error breaks the content editor experience such that media doesn't work any more, either.

My only review thing is that there's no test, but I won't set to NW over it.

nattyweb’s picture

Great - Patch #46 worked for me. Thank you.

Rafav’s picture

Hi,

I updated to 7.x-1.19 first and then 7.x-1.x-dev , been in drupal 7.69, and applied patch #68, but no luck, it still does not load toolbar, in the front, although I can see it perfectly well in the back:

front: https://i.imgur.com/Yw4GDAF.png
back: https://i.imgur.com/IfssYsK.png

I have install library full 4.14 in sites/all/libraries/ckeditor (tried several versions actually), console shows no js errors, drush ws no errors whatsoever, permissions are right. No custom configs.

Everything happened after upgrade from 1.18, been trying to fixed this for a week now, but I'ḿ quite lost. I could use some help....

benjbmc’s picture

The trick on #73 works for me, thanks @mchaplin !

jwilson3’s picture

Status: Reviewed & tested by the community » Needs work

I've tested this on my own project and can confirm that it does work with the following custom JS:

config.disallowedContent = 'img{width,height}';
config.image2_alignClasses = ['align-left', 'align-center', 'align-right'];

That being said, there are several formatting issues with the patch that should be addressed:

  1. +++ b/includes/ckeditor.lib.inc
    @@ -948,19 +948,50 @@ function ckeditor_profile_settings_compile($global_profile, $profile) {
    +    // Remove comments lines
    +    // multi-line
    +    $jsConf = preg_replace('#^/\*(?:[^*]*(?:\*(?!/))*)*\*/#m','', $conf['js_conf']);
    +    // single-line double slash
    +    $jsConf = preg_replace('#([;,{}()\[\]]|[\s\t]+)//.*[ \t]*#m','', $jsConf);
    

    Two points:

    1.- Each comment needs to be a complete sentence, ending in a period. Something like:

    // Remove multiple-line JavaScript comment blocks.
    // Remove single-line JavaScript comments.
    

    2.- $jsConf doesn't follow Drupal's PHP variable naming practices. This should be $js_conf.

  2. +++ b/includes/ckeditor.lib.inc
    @@ -948,19 +948,50 @@ function ckeditor_profile_settings_compile($global_profile, $profile) {
    +    // single-line hash
    +    $jsConf = preg_replace('/^[ \t]*#.*[ \t]*/m','', $jsConf);
    

    There is no such thing as a single-line hash comment in JavaScript. It seems like this was meant to strip PHP Hash comments, and someone got confused. If someone uses a hash and expects that to comment out a line, a JS parser will just give an error. There is a JavaScript Hashbang comment style but this is still kind of in the process of being vetted. I suppose it would be easy enough to update this regex to look for the #! pattern instead of just #, or just remove this entirely.

  3. +++ b/includes/ckeditor.lib.inc
    @@ -948,19 +948,50 @@ function ckeditor_profile_settings_compile($global_profile, $profile) {
    +    //$jsConf = preg_replace('/^#.*/','', $jsConf);
    

    No explanation why this line is commented out. It needs to be removed.

  4. +++ b/includes/ckeditor.lib.inc
    @@ -948,19 +948,50 @@ function ckeditor_profile_settings_compile($global_profile, $profile) {
    +    // Strip blank lines
    ...
    +        // Custom CKEditor setting concatenated
    ...
    +          // Special case for JS concatenated strings
    
    +++ b/includes/ckeditor.utils.js
    @@ -123,15 +136,87 @@ if (typeof window.CKEDITOR_BASEPATH === 'undefined') {
    +          // Try to replace all CKEDITOR. constants with their values
    ...
    +          // Special case for keystrokes
    ...
    +          // Case for use or config.XXX.concat() method
    

    Comments should be complete sentences and end in a period. But also, these comments do not really help explain what the code is doing. Its clear enough from just reading the code that an if statement for keystroke is exactly that: a special case for keystrokes. Maybe explain why its needed and what problem it solves.

  5. +++ b/includes/ckeditor.lib.inc
    @@ -948,19 +948,50 @@ function ckeditor_profile_settings_compile($global_profile, $profile) {
    +    $jsConf = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "", $jsConf);
    

    Should this regex also look for unix style line endings like \n instead of \r\n?

  6. +++ b/includes/ckeditor.utils.js
    @@ -123,15 +136,87 @@ if (typeof window.CKEDITOR_BASEPATH === 'undefined') {
    +          if (item.indexOf('<') > -1) { /* Found HTML string */
    ...
    +          } else { /* Custom JS */
    

    Inconsistent comment format.

  7. $dtd = [];
    ...
           // Custom CKEditor setting concatenated
            if (!empty($subMatches[2])) {
              foreach($subMatches[2] as $idx => $val) {
                $match = str_replace($subMatches[0][$idx], '', $match);
                $dtd[$subMatches[1][$idx]] = $val;
              }
            }
    

    DTD usually stands for Document Type Definition, and is specific for XML grammars. It is not clear why this variable name is used here. In general the section of code that deals with submatches is confusing and could use better documentation.

  8. diff --git a/includes/jqueryUI/sort.js b/includes/jqueryUI/sort.js
    index 0f4ab91..9d42d01 100644
    --- a/includes/jqueryUI/sort.js
    +++ b/includes/jqueryUI/sort.js
    @@ -147,14 +147,22 @@ jQuery(document).ready(function() {
         };
     
         if (typeof(Drupal.ckeditorToolbarToArray) == 'undefined') {
    -        Drupal.ckeditorToolbarToArray = function (toolbar) {
    -            toolbar = toolbar.replace(/\r?\n|\r/gmi, '')
    -                .replace(/\s/gmi, '')
    -                .replace(/([a-zA-Z0-9]+?):/g, '"$1":')
    -                .replace(/'/g, '"');
    -
    +      Drupal.ckeditorToolbarToArray = function (toolbar) {
    +        toolbar = toolbar.replace(/\r?\n|\r/gmi, '')
    +          .replace(/\s/gmi, '')
    +          .replace(/'/g, '"');
    +
    +        try {
    +          return JSON.parse(toolbar);
    +        } catch (e) {
    +          toolbar = toolbar.replace(/([a-zA-Z0-9]+?):/g, '"$1":')
    +          try {
                 return JSON.parse(toolbar);
    -        };
    +          } catch (e) {
    +            return toolbar;
    +          }
    +        }
    +      };
         }
    

    Yes, the standard way Drupal wants us to write JS is with 2-space indentation, however the entirety of the sort.js file uses 4-space indentation, so we should at least follow that instead of introducing inconsistency in this file. Fixing the spacing indentation for the entire file should be done in a follow-up issue.

jwilson3’s picture

I've fixed items 1,2,3,4,6,7,8 from #81.

Item #5 was a red herring. I misread the regular expression, where [\r\n]* the brackets imply you're looking for one or more sequential \r and/or \n.

jwilson3’s picture

Status: Needs work » Needs review
jcisio’s picture

Version: 7.x-1.19 » 7.x-1.x-dev
Status: Needs review » Needs work

Finally a real review after a lot of testing feedback. Thank you!

There are a few unrelated changes, like replace of double quotes with single quotes, where it is sure (luckily!). Leaving them will make the patch smaller and I think it is not a good moment for large patches ;-)

Besides, I wonder if we could add some tests to make sure that code works as expected, to avoid problem like 5/ in #81. I see that the regex was kept as-is, but I don't think it is correct. It replaces "A\n\nB" with "AB" instead of the expected "A\nB". And a simpler (and correct?) regex, works with both Windows and UNIX (but not Mac's \r) line terminators, could be preg_replace("/(\s*\r?\n){2}/", "\n", $text).

jwilson3’s picture

Title: Javascript Error » Valid JS configurations in js_conf break parser
Issue summary: View changes

Was having trouble re-finding this issue, so update issue title and summary.

jwilson3’s picture

Issue summary: View changes
jwilson3’s picture

I can't help thinking that there has got to be a better way to do this — ie, converting JS to PHP only to eventually go back to JS — that avoids any regression on the security concerns, but also leaves us without having to maintain custom JS-syntax parser/handler.

cabplan’s picture

#46 patch worked for me, using the "git apply -v [patchname.patch]" from the instructions from the module page: https://www.drupal.org/project/ckeditor/git-instructions

vokiel’s picture

StatusFileSize
new9.48 KB

I'm attaching new patch with changes from @jwilson3 and a bit more comments from me.

As for the \r\n regex, it is processing content sent from the Custom JavaScript configuration textarea (not a raw file), which by the defition of HTML standards always contains CR+LF:

It is normalized so that line breaks use U+000D CARRIAGE RETURN U+000A LINE FEED (CRLF) character pairs

hubbs’s picture

#89 worked for me. Thank you!

For what it's worth, the "trick" in #73 doesn't work. If you remove the ; from CKEDITOR.dtd.$removeEmpty.i = 0;, any time you try enter source mode and paste in a fontawesome icon (i.e. <i class="fas fa-adjust"></i>) the icon will be stripped out once you leave source mode.

jcisio’s picture

Status: Needs work » Needs review
jwilson3’s picture

An interdiff between #82 and #89 would really facilitate reviews.

mile23’s picture

StatusFileSize
new5.74 KB

Interdiff #82 to #89.

Interdiff howto: https://www.drupal.org/documentation/git/interdiff

jwilson3’s picture

Status: Needs review » Needs work
  1. +++ b/includes/ckeditor.lib.inc
    @@ -948,28 +948,28 @@ function ckeditor_profile_settings_compile($global_profile, $profile) {
    +    // CKEDITOR.dtd holds and object representation of the HTML DTD to be used by the editor in its internal operations.
    +    // See more at https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_dtd.html
    
    @@ -983,16 +983,21 @@ function ckeditor_profile_settings_compile($global_profile, $profile) {
    +          // Special case for JS concatenated strings.
    +          // For example, one can have config.colorButton_colors defined as below, which would cause parsing problems.
    +          //     config.colorButton_colors = 'B3B3B3,'+'000,800000,696969,'+'F00,FF8C00'
    +          // This regex will replace it into single string:
    +          //     config.colorButton_colors = 'B3B3B3,000,800000,696969,F00,FF8C00'
    
    +++ b/includes/ckeditor.utils.js
    @@ -154,7 +154,7 @@ if (typeof window.CKEDITOR_BASEPATH === 'undefined') {
    -          // Try to replace all CKEDITOR. constants with their values
    +          // Try to replace all CKEDITOR. constants with their values.
    
    @@ -163,7 +163,7 @@ if (typeof window.CKEDITOR_BASEPATH === 'undefined') {
    -          // Special case for keystrokes
    +          // Special case for keystrokes.
    
    @@ -189,7 +189,7 @@ if (typeof window.CKEDITOR_BASEPATH === 'undefined') {
    -          // Case for use or config.XXX.concat() method
    +          // Case for use or config.XXX.concat() method.
    

    AFAICT the relevant changes in #89 are comment improvements.

    In my opinion we should take these couple comments and add them to #82 and create a new patch. Then create an interdiff between #82 and #89

  2. +++ b/includes/ckeditor.lib.inc
    @@ -948,28 +948,28 @@ function ckeditor_profile_settings_compile($global_profile, $profile) {
    -    $js_conf = $conf['js_conf'];
    ...
    -    $js_conf = preg_replace('#^/\*(?:[^*]*(?:\*(?!/))*)*\*/#m', '', $js_conf);
    -    // Remove single-line JavaScript comments.
    ...
    +    $js_conf = preg_replace('#^/\*(?:[^*]*(?:\*(?!/))*)*\*/#m','', $conf['js_conf']);
    +    // Remove multiple-line JavaScript comment blocks.
    +    $js_conf = preg_replace('#([;,{}()\[\]]|[\s\t]+)//.*[ \t]*#m','', $js_conf);
    ...
    -    $js_conf = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", '', $js_conf);
    +    $js_conf = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "", $js_conf);
    ...
    -        $match = rtrim($match, ';') . ';';
    -
    +        $match = rtrim($match, ';').';';
    +        preg_match_all('#(CKEDITOR\.+[\w\.\$]+[\s]*)=[\s]*(.+?);[\s]*(?=CKEDITOR\.|\/\/|\/*$)#is', $match, $subMatches);
    ...
    -        preg_match_all('#(CKEDITOR\.+[\w\.\$]+[\s]*)=[\s]*(.+?);[\s]*(?=CKEDITOR\.|\/\/|\/*$)#is', $match, $sub_matches);
    

    Several code formatting changes I made in #82 have been removed.

  3. +++ b/includes/ckeditor.lib.inc
    @@ -948,28 +948,28 @@ function ckeditor_profile_settings_compile($global_profile, $profile) {
    -    // Remove single-line JavaScript comments.
    -    $js_conf = preg_replace('#([;,{}()\[\]]|[\s\t]+)//.*[ \t]*#m', '', $js_conf);
    ...
    +    // Remove multiple-line JavaScript comment blocks.
    +    $js_conf = preg_replace('#([;,{}()\[\]]|[\s\t]+)//.*[ \t]*#m','', $js_conf);
    

    Why was this hunk changed from single-line to multiple-line JavaScript comment blocks?

  4. +++ b/includes/ckeditor.lib.inc
    @@ -948,28 +948,28 @@ function ckeditor_profile_settings_compile($global_profile, $profile) {
    -        if (!empty($sub_matches[2])) {
    -          foreach ($sub_matches[2] as $j => $sub_match) {
    -            $match = str_replace($sub_matches[0][$j], '', $match);
    -            $dtd[$sub_matches[1][$j]] = $sub_match;
    +        if (!empty($subMatches[2])) {
    +          foreach($subMatches[2] as $idx => $val) {
    +            $match = str_replace($subMatches[0][$idx], '', $match);
    +            $dtd[$subMatches[1][$idx]] = $val;
    

    $idx is not a standard key in Drupal for loops. I switched this to $j for a purpose. It also provides context so the user knows immediately that they're inside another for loop ($i signifying the outer loop).

  5. +++ b/includes/ckeditor.lib.inc
    @@ -983,16 +983,21 @@ function ckeditor_profile_settings_compile($global_profile, $profile) {
    -        elseif (preg_match('#["|\'][\s]*\+[\s]*["|\']#is', $value)) {
    +        else if ( preg_match('#["|\'][\s]*\+[\s]*["|\']#is', $value)) {
    

    Use elseif instead of else if. Coding Standards reference.

  6. +++ b/includes/ckeditor.lib.inc
    @@ -983,16 +983,21 @@ function ckeditor_profile_settings_compile($global_profile, $profile) {
    -        $settings['js_conf'][$matches[1][$i]] = $value;
    +        $settings["js_conf"][$matches[1][$i]] = $value;
    ...
    -      $settings['js_conf']['dtd'] = $dtd;
    +      $settings["js_conf"]["dtd"] = $dtd;
    

    Single quote strings should be used by default.

  7. +++ b/includes/ckeditor.utils.js
    @@ -203,20 +203,17 @@ if (typeof window.CKEDITOR_BASEPATH === 'undefined') {
    -          // String is HTML.
               if (item.indexOf('<') > -1) {
    +            // Found HTML string.
                 data = item.replace(/(^['|"]|['|"]$)/g, '');
    -          }
    -          // String contains a JS function.
    -          else if (item.indexOf('function(') > -1) {
    +          } else if (item.indexOf('function(') > -1) {
    +            // Found JavaScript function.
                 data = (new Function('"use strict"; return '+item)());
    ...
    -          else if (item.charAt(0) === '{' || item.charAt(0) === '[') {
    +          } else if (item.charAt(0) === '{' || item.charAt(0) === '[') {
    +            // Found JavaScript abject or array.
                 data = Drupal.ckeditorToolbarToArray(item);
    -          }
    -          // Fallback to the default of simple JS variable.
    -          else {
    +          } else {
    +            // Custom JavaScript.
                 try {
    

    Any reason this hunk was changed? If not it should be reverted to how it was in #82.

sgdev’s picture

While I understand @jwilson3's feedback on #94 and wanting to improve, I also would like to confirm patch #89 works for me.

gnuget’s picture

#94 is working for me as well.

Thanks!

vokiel’s picture

Status: Needs work » Needs review
StatusFileSize
new9.62 KB
new2.16 KB

I'm sorry for accidentally dropping changes from #82.

The new patch contains all the changes. The interdiff shows that changes from #82 are preserved now, with comment improvements.

Mentor.37’s picture

I have applied patch #97 and in my custom js I have:
config.font_names = 'newfont1;' + 'newfont2;' + CKEDITOR.config.font_names;

in way to add my two new fonts at the CKEDITOR standard ones, but now the variable CKEDITOR.config.font_names stopped working and in my font dropdown list i have:

- newfont1
- newfont2
- ' + config.font_names

If I edit my custom js in this way:
config.font_names = CKEDITOR.config.font_names.concat( [ 'newfont1;' ], [ 'newfont2;' ] );
in my font dropdown list i have:

- list of ckeditor fonts
- newfont2

but it misses newfont1, it only appears if I edit my js in this way:
config.font_names = CKEDITOR.config.font_names.concat( [ 'newfont1;' ], [ 'newfont1;' ], [ 'newfont2;' ] );

alexh’s picture

Thank you very much, patch #97 fixed all errors in my case.

vokiel’s picture

@Mentor.37 please try with semicolon at the front (because the default font_names does not end with semicolon):

config.font_names =  CKEDITOR.config.font_names.concat( [ ';newfont1' ],  [ ';newfont2' ] );

  • vokiel committed bb0484b on 7.x-1.x
    Issue #3120705 by vokiel, jwilson3, Mile23: Valid JS configurations in...
vokiel’s picture

Status: Needs review » Fixed

I'm pushing the changes as it's been 3 months since the last comment and patch.

Reviewed the history and seems that all issues have been addressed and resolved.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.