Problem/Motivation
When validating a filter format's edit page, entity_embed_filter_format_edit_form_validate() fails to account for a scenario where 'filter_html' is enabled with <drupal-entity> allowed as an element with no allowed attributes.
If <drupal-entity> is allowed but with no attributes, then $allowed['drupal-entity'] will be false. As a result, array_keys($allowed['drupal-entity']) will return null. As a result, when $missing_attributes is generated using an array_diff on null, it returns null, which causes the validation to incorrectly pass.
Steps to reproduce
- Create a filter format with 'filter_html' enabled.
- Add an Entity Embed button to the WYSIWYG.
- Display embedded entities
- Allow
<drupal-entity>but do not allow any attributes - Save
- Observe the form passes validation when it should not
Proposed resolution
Allow for a situation where <drupal-entity> has no allowed attributed so that validation then fails.
Remaining tasks
Submit patch
Update tests once initial review is complete
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | entity_embed-validation_check_drupal_entity_attributes-3060729-2.patch | 974 bytes | chris burge |
Comments
Comment #2
chris burge commentedComment #3
oknateUsing your steps in issue summary, it should pass, as you don't specify that the 'Display embedded entities' checkbox should be checked. Without that filter, it shouldn't care what you do with the tag.
Actually I'm wrong, it should show an error that the button requires the entity embed filter.
Comment #4
chris burge commentedSteps to Reproduce have been updated.
I submitted this patch, along with one for #3060728: entity_embed_filter_format_edit_form_validate() should check if 'filter_html' is enabled before validating, separately because they are two separate bugs, but looking at #3060728-6: entity_embed_filter_format_edit_form_validate() should check if 'filter_html' is enabled before validating, I can see that the fix for one necessarily affects the other. I'm going to roll these patches into a single issue/patch.
Comment #5
oknateI'm still trying to wrap my head around the bugs.
Comment #6
oknateSteps to reproduce:
1) go to /admin/config/content/formats/add
1.5) set Name field.
2) select CKEditor
3) Drag an entity embed button to active toolbar
4) check 'Limit allowed HTML tags and correct faulty HTML'
5) set "Allowed HTML tags" to
<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type='1 A I'> <li> <dl> <dt> <dd> <h2 id='jump-*'> <h3 id> <h4 id> <h5 id> <h6 id> <drupal-entity>6) press "Save configuration"
Expected, there should be an error that the button requires the entity_embed filter.
7) Reopen button
8) Observe the Allowed HTML tags have been automatically changed for you.
<drupal-entity data-entity-type data-entity-uuid data-entity-embed-display data-entity-embed-display-settings data-align data-caption data-embed-button data-langcode alt title>9) Again remove all the attributes from the drupal entity, set it back to
<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type='1 A I'> <li> <dl> <dt> <dd> <h2 id='jump-*'> <h3 id> <h4 id> <h5 id> <h6 id> <drupal-entity>10) press "Save configuration"
Now you get the expected error.
So the bug seems to be when you initially don't check 'Display embedded entities' and manually set 'drupal-entity' element, you trick it into not validating.
Oh, and this is with the patch.
Comment #7
oknateOk, I can confirm the test case in the issue now. It passes validation despite the missing attributes having been removed.
But upon reopening the form, it looks like it added the attributes.
If I remove the attributes again and save, I get this error:
Which is the wrong error.
Comment #8
oknateTesting again with the issue summary steps, I can confirm, it wrongly passes validation, and saves allowed_html without the attributes in the filter.format.filter_name.yml.
But the patch doesn't fix the validation issue yet.
Comment #9
chris burge commentedClosing in favor of #3060749: entity_embed_filter_format_edit_form_validate() Logic is Faulty, which combines this issue with #3060728: entity_embed_filter_format_edit_form_validate() should check if 'filter_html' is enabled before validating.
@oknate - thanks for digging into this issue.
Comment #10
chris burge commented