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
Comment #2
vokielWhat is your toolbar setting?
Could you set a breakpoint at this line
ckeditor.utils.js?q7esz7:134and dumptextarea_settingsandadd_confvariables?Comment #3
sbwildflowers commentedI'm also seeing this error. My admin config area looks like this:
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.
Comment #4
yntun commentedI 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.
Comment #5
vokiel@yntun could you please attach your file, I'm working on the solution and the more use-cases the better.
Comment #6
alex g commentedRemoving our custom JS config helped.
@vokiel For your reference.
These 2 lines seems to be the culprit in my first use case.
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.
Comment #7
geophysicist commentedThere is absolutely different handler to add custom settings. Was:
now:
In a case in configs you have not just string like in my case:
Replace it to:
It works in my case.
Comment #8
ezoulou commented+ 1 for comment #4 (remove commented lines in custom config).
Thanks
Comment #9
mpranj commentedComment #4 worked for me as well. Thank you! No idea where the custom config even came from.
Comment #10
vokielAttaching 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?
Comment #11
geophysicist commented@vokiel, looks like it works for me. #10 patch is applied and configs reverted back
Comment #12
flotsam commentedI 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
Patch from #10 did not change the error, and CKEditor does not load.
Comment #13
tmin commented@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.
Comment #14
sbwildflowers commented@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:
Comment #15
caspervoogt commentedhad 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.
Comment #16
bazzmann commentedHi 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:
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?
Comment #17
vokiel@bazzmann have you tried with the patch? I just check your config and it seems to be working fine with the patch.
Comment #18
kaosagnt commentedPatch 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.
Comment #19
RaySilver commentedSame 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?
Comment #20
yntun commented@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.
Comment #21
ctrnz commentedAlso got
textarea_settings.js_conf[add_conf].replace is not a functionChanging
textarea_settings['js_conf'][add_conf].replace(/'/g, '"');totextarea_settings['js_conf'][add_conf].toString().replace(/'/g, '"');seems to fix an issue.Still testing rest of functionalities.
Comment #22
vokielI'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.
Comment #23
sthomen commented#22 seems to have fixed the problem with
textarea_settings.js_conf[add_conf].replace is not a functionfor me. Thank you.Comment #24
marcopbazz commentedTryed 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:
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
Comment #25
giuvax commentedSame here. On one of my website CK Editor won't load. I get this.
Comment #26
giuvax commentedI just use the patch for ckeditor.utils.js and it loaded. Should I edit the other file too?
Comment #27
flotsam commentedUsing 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).
Comment #28
bazzmann commented@vokiel, as @marcopbazz told, there is no resolution using one of the patch here present.
No one optional parameter seems to be working.
Comment #29
caspervoogt commentedthe patch from #22 solved the "replace" JS error for me
Comment #30
kruser commentedPatch #22 fixed all my sites! thanks.
Comment #31
vokielHuge 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.dtdso you can keep it.Please all involved try the newest patch with your original configurations.
Comment #32
vokielComment #33
marcopbazz commentedPatch #31 worked for me!
Comment #34
mchaplin commentedWhen's the release that contains #31 patch?
Comment #35
vokiel@mchaplin this week for sure, just want to gather more feedback.
Comment #36
jrearickI 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( [[ ‘α', 'Greek small letter alpha' ], [ ‘β', 'Greek small letter beta' ]] );With the following error on unpatched:
I'll defer to your judgement for marking this RTBC. Thanks @vokiel for taking this on!
Comment #37
kualeeI 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
I had similar error message as in the original issue summary before applying the patch
Uncaught SyntaxError: Unexpected token ; in JSON at position 5Comment #38
yntun commented@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.
Comment #39
vokiel@jrearick you don't need to use full
CKEDITOR.configchain, as config is parsed withing theCKEDITORobject available.Instead
CKEDITOR.config.specialChars = CKEDITOR.config.specialChars.concat( [[ ‘α', 'Greek small letter alpha' ], [ ‘β', 'Greek small letter beta' ]] );just use this:
config.specialChars = config.specialChars.concat( [[ "α", "Greek small letter alpha" ], [ "β", "Greek small letter beta" ]] );@yntun can you paste here your config so I can debug it?
Comment #40
aidas85 commentedHi,
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:
Comment #41
vokiel@aidas85 look at my post #39.
instead of
CKEDITOR.config.contentsCss = [CKEDITOR.config.contentsCss, 'my.css'];use
config.contentsCss = config.contentsCss.concat( ['my.css'] );Comment #42
vokielAn 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
Arraybased settings, like:config.specialChars = config.specialChars.concat( [ '"', [ '’', 'Custom label' ] ] );Comment #43
javmorais commentedHi,
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:
Code of "/includes/ckeditor.lib.inc" file:
lines 179 to 186
lines 607 to 615
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
Comment #44
vokiel@javmorais I'm sorry, I generated the patch from current dev instead of last release. The new patch should be fine now.
Comment #45
javmorais commented@vokiel thanks for your response!!
I can't see the new patch. Do you mean you will generate it?
Regards
Javi
Comment #46
vokielComment #47
gyogyika commentedPatch #46 worked for me!
Comment #48
javmorais commentedHi,
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
Comment #49
insanityinside commentedI'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.The toString method above by @ctrnz solves the issue.
Comment #50
mario steinitzAfter 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:
Comment #51
javmorais commentedHi,
@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
Comment #52
freddyedu commentedHi,
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.
Comment #53
kualeeI 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
Comment #54
thatguy commentedI 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?
Comment #55
aidas85 commentedUsing 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.
Comment #56
javmorais commentedHi,
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):
But I don't know if option 2 has any security issue. I'm waiting for someone to answer #51
Regards
Javi
Comment #57
teebo commentedPersonally, #6 temporarily fixes the issue:
Enabling empty (i or span) tags was also my issue.
All other configs starting with config.xxx were accepted.
Comment #58
aiglesiasn commentedHi!
I used patch #46, and my site works again properly.
Thank you very much for the update!
Andrés
Comment #59
candelas commentedThanks @vokiel patch #46 worked perfect
Comment #60
subham1707 commentedHi,
It worked for me too.
Thanks,
Comment #61
vokiel@Mario Steinitz predefined styles should be added to
ckeditor.styles.jsand 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
dtdsettings. They should work now.The
config.AllowedContentcan be set inAllowed content filter administration panel section. No need to add this to custom JavaScript.Comment #62
javmorais commentedHi @vokiel,
Thanks for your response.
My problem is only when I have Custom JavaScript configuration. This is my custom JavaScript configuration:
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
Comment #63
Sylense commentedThe 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.
Comment #64
javmorais commentedHi,
@Sylense, had you tried my last suggestion in #62? My problem only was the last line in my custom JavaScript configuration
Regards,
Javi.
Comment #65
mchaplin commentedHi @vokiel what's the latest on a release for this issue?
Thanks Mike
Comment #66
Sylense commented@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.
Comment #67
javmorais commentedHi,
@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
Comment #68
vokielAttaching 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
CKEDITORnamespace should be used only for theCKEDITOR.dtdwhich is not a config option, but used here quite often so it got custom processing. Others should be simplified to use just theconfig.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.
Comment #69
jrearickHuh, 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( [[ 'α', 'Greek small letter alpha' ], [ 'β', 'Greek small letter beta' ]] );Even with the CKEDITOR. prefix, it still worked...
CKEDITOR.config.specialChars = CKEDITOR.config.specialChars.concat( [[ 'α', 'Greek small letter alpha' ], [ 'β', 'Greek small letter beta' ]] );And the CKEDITOR.dtd seems to have worked:
FWIW, I approve.
Hopefully, @javmorais can test this patch as well.
Comment #70
jrearickComment #71
theorichel commentedHad the same problem with v 1.19 and removing the customization of my Config file did the trick. Thanks Vokiel!
Comment #72
jrearickThere 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.
Comment #73
mchaplin commentedFor 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
Comment #74
jrearick@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
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.
Comment #75
zoraxI confirm #73 save my night...
Thanks mchaplin !
Comment #76
oranges13Updating 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.
Comment #77
mile23+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.
Comment #78
nattyweb commentedGreat - Patch #46 worked for me. Thank you.
Comment #79
Rafav commentedHi,
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....
Comment #80
benjbmc commentedThe trick on #73 works for me, thanks @mchaplin !
Comment #81
jwilson3I've tested this on my own project and can confirm that it does work with the following custom JS:
That being said, there are several formatting issues with the patch that should be addressed:
Two points:
1.- Each comment needs to be a complete sentence, ending in a period. Something like:
2.-
$jsConfdoesn't follow Drupal's PHP variable naming practices. This should be$js_conf.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.No explanation why this line is commented out. It needs to be removed.
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.
Should this regex also look for unix style line endings like
\ninstead of\r\n?Inconsistent comment format.
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.
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.
Comment #82
jwilson3I'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\rand/or\n.Comment #83
jwilson3Comment #84
jcisio commentedFinally 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).Comment #85
jwilson3Was having trouble re-finding this issue, so update issue title and summary.
Comment #86
jwilson3Comment #87
jwilson3I 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.
Comment #88
cabplan commented#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
Comment #89
vokielI'm attaching new patch with changes from @jwilson3 and a bit more comments from me.
As for the
\r\nregex, it is processing content sent from the Custom JavaScript configuration textarea (not a raw file), which by the defition of HTML standards always containsCR+LF:Comment #90
hubbs commented#89 worked for me. Thank you!
For what it's worth, the "trick" in #73 doesn't work. If you remove the
;fromCKEDITOR.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.Comment #91
jcisio commentedComment #92
jwilson3An interdiff between #82 and #89 would really facilitate reviews.
Comment #93
mile23Interdiff #82 to #89.
Interdiff howto: https://www.drupal.org/documentation/git/interdiff
Comment #94
jwilson3AFAICT 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
Several code formatting changes I made in #82 have been removed.
Why was this hunk changed from single-line to multiple-line JavaScript comment blocks?
$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).
Use elseif instead of else if. Coding Standards reference.
Single quote strings should be used by default.
Any reason this hunk was changed? If not it should be reverted to how it was in #82.
Comment #95
sgdev commentedWhile I understand @jwilson3's feedback on #94 and wanting to improve, I also would like to confirm patch #89 works for me.
Comment #96
gnuget#94 is working for me as well.
Thanks!
Comment #97
vokielI'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.
Comment #98
Mentor.37 commentedI 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:
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:
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;' ] );Comment #99
alexh commentedThank you very much, patch #97 fixed all errors in my case.
Comment #100
vokiel@Mentor.37 please try with semicolon at the front (because the default font_names does not end with semicolon):
Comment #102
vokielI'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.