Problem/Motivation
I tried to adjust a style dropdown class for the CKEditor but it didn't seem to work even thought the settings were saved.
After opening the JS console inside the Text Formatters Form page I got the following error:
Uncaught TypeError: Cannot read property 'tagName' of null
at Object._parseSetting (filter.filter_html.admin.js?v=8.9.6:142)
at HTMLTextAreaElement. (filter.filter_html.admin.js?v=8.9.6:41)
My current list of allowed HTML Tags is:
<a href hreflang target class id rel> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <s> <sup> <sub> <img src alt data-entity-type data-entity-uuid data-align data-caption> <table> <caption> <tbody> <thead> <tfoot> <th> <td> <tr> <hr> <p> <br> <h1> <pre> <drupal-entity data-entity-type data-entity-uuid data-entity-embed-display data-entity-embed-display-settings data-align data-caption data-embed-button title alt> <div style> <iframe src width height style frameBorder class allowFullScreen> <drupal-media data-entity-type data-entity-uuid>
Saving the form produces no errors whatsoever
The file the error is referencing is /core/modules/filter/filter.filter_html.admin.js
This is happening on multiple Drupal 8.9.6 installations as well as on a fresh Drupal 9.0.6 installation.
What is happening
Basically the following code is executed per given HTML Tag
//var sandbox = document.createElement('div');
//sandbox.innerHTML = '<caption>';
//node = sandbox.firstChild;
//tag = node.tagName;
Here the example <caption> creates the first error.
I also encountered that problem with the <tbody> tag.
It seems for some reason the browser isn't allowed or able to create some given HTML tags in a sandbox. Dont know why.
You can try the list given above to see if there are more HTML tags which produce this error.
Since this is a Frontend-JS Logic (which depends on used browser and version) I think checking the allowed HTML Tags would be better suited to be handled in the backend.
Comments
Comment #2
kevin.pfeifer commentedComment #3
kevin.pfeifer commentedSeems like this is a duplicate of https://www.drupal.org/project/drupal/issues/2556069
Thx to @james.williams to point that out!
Comment #4
kevin.pfeifer commented