When you add 'class' as an allowed attribute in Basic HTML and save, it changes to class=""

Steps to reproduce:

  1. Edit the Basic HTML filter
  2. Add class to the allowed attributes of a tags
  3. Save
  4. class is changed to class=""

Screenshot of input before save:

Screenshot after save:

I note that the filter still works; I can still use the class attribute on a tags.

Original summary
---

Hi, sorry, my english is not perfect. Be indulgent.

After a fresh install of Drupal 8.0.5, i try to add some attributes to "a" html tags (title, class, id, rel, target) . This works, but for class attributes, it's save with additionnal string ="" (see attachment). It's added in Basic HTML text format. I do the same with Restricted HTML and it's ok.

Comments

yolker created an issue. See original summary.

wim leers’s picture

Component: filter.module » editor.module
Issue tags: +Needs steps to reproduce

Good catch!

RemyAroundTown’s picture

I was able to reproduce this in 8.1. From the configuration screen for a text format, adding class as an attribute to any tag in the allowed tags list results in class="" being saved instead.

hershey.k’s picture

Assigned: Unassigned » hershey.k

Going to try and reproduce and attempt to fix the issue.

chiranjeeb2410’s picture

@yolker, which file needs to be considered for this fix?

oeklesund’s picture

StatusFileSize
new782 bytes

This should prevent the issue.

oeklesund’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 6: added_to_class-2693659-6.patch, failed testing. View results

chiranjeeb2410’s picture

Status: Needs work » Needs review
StatusFileSize
new780 bytes

Patch uploaded against 8.1 core as mentioned by @RemyAroundTown in #3.
Review accordingly.

chiranjeeb2410’s picture

StatusFileSize
new637 bytes

Should do the trick. Please review.

ethomas08’s picture

Testing on D8.6 and am not able to reproduce the bug. The code looks different so it looks like things must have been fixed at some point with updates. Screenshot attached to show that I could save a class added to the "a" in my filter settings.

ethomas08’s picture

StatusFileSize
new161.98 KB

Screenshot png is called "class_is_saved"

alonaoneill’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
pcate’s picture

I used to have this issue, but like @ethomas08 I tested removing the =“” and reexporting config today with a site running 8.6, and the issue is no longer occurring.

The original config was exported when the site was running 8.4.

kostyashupenko’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new780 bytes
alonaoneill’s picture

Patch applied on 8.8x!

cilefen’s picture

Version: 8.0.5 » 8.8.x-dev
Component: editor.module » filter.module
Assigned: hershey.k » Unassigned

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

pameeela’s picture

Title: Added ="" to class attributes in "Limit allowed HTML tags ..." » Empty quotes get added to class attribute in "Limit allowed HTML tags"
Issue summary: View changes
Issue tags: -Needs steps to reproduce
StatusFileSize
new25.72 KB
new26.03 KB

I can reproduce this so I updated IS with screenshots.

But as I note in the IS, the filter still works; I can still use the class attribute on a tags, so I am not sure that this needs to be fixed? It doesn't seem to be causing any problems.

pameeela’s picture

Issue tags: +Bug Smash Initiative

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

ranjith_kumar_k_u’s picture

StatusFileSize
new646 bytes
new13.11 MB

The last patch failed to apply on 9.2 ,re-rolled for 9.2
after patch

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

@ranjith_kumar_k_u, thanks for your interest in this issue. The latest patch didn't pass the coding standards check. Have a look at the instructions for running the coding standard checks locally so you can be sure the tests will run before uploading a patch. It also has the advantage of saving resources, including money, for the Drupal association. There are real costs for running the tests. And add an interdiff or a diff when doing a reroll. That will make it easier for the reviewer.

yedhukrishnan.p@valuebound.com’s picture

Status: Needs work » Needs review
StatusFileSize
new811 bytes
new377 bytes
new116.44 KB

I could not find any coding standard issues apart from the one that I have attached as screenshot image. Please review.

jofitz’s picture

Issue tags: -Needs reroll
StatusFileSize
new1.45 KB

Include es6 changes in patch

gauravvvv’s picture

StatusFileSize
new1.46 KB
new1.23 KB

Patch added, Interdiff attached for patch 26_28.

longwave’s picture

Status: Needs review » Needs work

The ES6 code fails our style guidelines:

/var/www/html/core/modules/filter/filter.filter_html.admin.es6.js
  341:13  error  All 'var' declarations must be at the top of the function scope  vars-on-top
  341:13  error  Unexpected var, use let or const instead                         no-var
  343:41  error  Unexpected string concatenation                                  prefer-template
vsujeetkumar’s picture

Status: Needs work » Needs review
StatusFileSize
new1.46 KB
new1.37 KB

Fixed the ES6 code fails, Please have a look.

longwave’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Thanks. I guess this needs a functional JavaScript test to ensure we don't break it again in the future. There is already a JS test for the HTML filter so it should be possible to extend that.

vsujeetkumar’s picture

Status: Needs work » Needs review
StatusFileSize
new5.04 KB
new3.41 KB

Added Tests, Please have a look.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Believe this is a duplicate of https://www.drupal.org/project/drupal/issues/2710427#comment-14627888 or also being solved over there. Could someone confirm?

darvanen’s picture

Status: Needs review » Closed (duplicate)

I agree with @smustgrave, this is a duplicate of #2710427: Broken "Allowed Tags" updating: after all values for an attribute are allowed, it should not be overridden to allow only certain attribute values.

I would normally favour the issue that was opened earlier (this one) but in this case the other ticket has a more fleshed out issue summary and a good deal more recent discussion, so closing this ticket instead.

We have asked in #bugsmash for credit to be transferred from this ticket to that one.

quietone’s picture

Moving credit