Problem/Motivation

See #3222852-17: <dl> <dt> <dd> by introducing "Manually editable HTML tags" configuration on Source Editing.

There's currently a lack of clarity in the half a dozen methods on HTMLRestrictionsUtilities. \Drupal\ckeditor5\Plugin\CKEditor5PluginManager::getReadableElements() and \Drupal\ckeditor5\Plugin\CKEditor5PluginManager::getBlockElementList() should also be refactored out of there.

IMHO by far the clearest solution here is to stop treating this specially structured as an array. We already started doing that by introducing that utility class in the first place in #3216015: Generate CKEditor 5 configuration based on pre-existing text format configuration, where we added \Drupal\ckeditor5\HTMLRestrictionsUtilities::diffAllowedElements(). #3222852: <dl> <dt> <dd> by introducing "Manually editable HTML tags" configuration on Source Editing made it grow a lot, and just made it clear we really need better developer ergonomics around this — the risk of bugs is otherwise very high.

Therefore I think introducing a HTMLRestrictions value object would make this a lot less brittle, and far simpler to test:

final class HTMLRestrictions {

  public static function create(string $string): HTMLRestrictions;

  public function diff(HTMLRestrictions $other): HTMLRestrictions;

  public function intersect(HTMLRestrictions $other): HTMLRestrictions;

  public function toCKEditor5ElementsArray(): string[];

  public function toFilterHtmlAllowedTagsArray(): string[];

  public function toGeneralHtmlSupportConfig(): string[];

}

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork drupal-3228334

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Issue fork ckeditor5-3228334

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Wim Leers created an issue. See original summary.

Wim Leers’s picture

Issue tags: +Needs tests

And as @bnjmnm pointed out: this allows us to add unit tests too! :)

Wim Leers’s picture

Title: Refactor HTMLRestrictionsUtilities to a HtmlRestrictions value object » [PP-1] Refactor HTMLRestrictionsUtilities to a HtmlRestrictions value object
Assigned: Unassigned » Wim Leers
Related issues: +#3231327: Plugin definition DX: validate ckeditor5.drupal.elements items

While working on this, identified #3231327-13: Plugin definition DX: validate ckeditor5.drupal.elements items . That will mean one less HTMLRestrictionsUtilities call to convert.

Wim Leers’s picture

I've been working on unit tests first and foremost and have found some issues. Doing this refactor will make it far easier to detect those subtle bugs ahead of time, that would also make the automatic upgrade path not fail in those subtly broken ways (when it comes to interpreting differences between two sets of HTML restrictions, to determine what the appropriate course of action is during the automatic upgrade path).

More news tomorrow.

Wim Leers’s picture

Wim Leers credited bnjmnm.

Wim Leers’s picture

Crediting Ben and I already, for the work that led to this issue.

Wim Leers’s picture

Yay, the unit test is working, and already finding problems! 🤓🥳

Wim Leers’s picture

The new unit test's results before 88b0f21ed7bfe56a0479063bcd51b3d423572ee4 ("Fix ::intersect()"):

...........F...F.......F.....F.......FF.FFFF                      44 / 44 (100%)

vs after:

...........F...F.......F.....F..............                      44 / 44 (100%)

Progress!

Wim Leers’s picture

larowlan’s picture

Title: [PP-1] Refactor HTMLRestrictionsUtilities to a HtmlRestrictions value object » Refactor HTMLRestrictionsUtilities to a HtmlRestrictions value object
Wim Leers’s picture

Per #3249240-21: HTMLRestrictionsUtilities:: providedElementsAttributes() causes deprecations on PHP 8.1 by @larowlan: this is considered important by core committers. Not in the least because not having this done already meant it was pretty painful to figure out what were the acceptable changes to get the current code to work on PHP 8.1.

Wim Leers’s picture

Project: CKEditor 5 » Drupal core
Version: 1.0.x-dev » 9.3.x-dev
Component: Code » ckeditor5.module
Status: Active » Needs work

I'm working on the port of this MR!

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.

Wim Leers’s picture

Looks like I triggered an infinite retesting loop in DrupalCI: https://www.drupal.org/pift-ci-job/2289771https://dispatcher.drupalci.org/job/drupal_patches/109074/console + https://dispatcher.drupalci.org/job/drupal_patches/109076/console + https://dispatcher.drupalci.org/job/drupal_patches/109077/

🙈

Asked in #drupal-infrastructure on Slack to stop it — I don't have the power.

But … at least locally, I'm now seeing

Testing /Users/wim.leers/Work/d8/core/modules/ckeditor5/tests/src/Unit
...........F...F.......F.....F..............                      44 / 44 (100%)

Time: 2.37 seconds, Memory: 8.00 MB

There were 4 failures:

which is identical to what I had in #10 👍 (and also identical to the last test result that was tested against the contrib project: https://www.drupal.org/pift-ci-job/2211769 for https://git.drupalcode.org/project/ckeditor5/-/merge_requests/130/diffs?...)

Wim Leers’s picture

Yay, tests are working now! The new test case I added based on the bug report in #3256616: AssertionError: assert($value === TRUE || Inspector::assertAllStrings($value)) in assert() (line 242 of core/modules/ckeditor5/src/HTMLRestrictionsUtilities.php) is passing. So this will fix that issue too. Marked that issue as a duplicate.

Please also credit beatrizrodrigues and DieterHolvoet for their work on that issue! 🙏

tim.plunkett’s picture

beatrizrodrigues’s picture

thank you @Wim Leers and @tim.plunkett :)

DieterHolvoet’s picture

Thanks for the credits and the quick fix!

Wim Leers’s picture

76d34c21 added much-needed validation that will prevent much future pain. It caused a significant number of additional tests to fail.

4970a06a fixed the bugs that the new validation uncovered.

c65b4550 added more test coverage that I realized was necessary thanks to the preceding commit, which in turn caused more fixes.

Wim Leers’s picture

Issue tags: -Needs tests

05310198 added test coverage for HTMLRestrictions::union(), which was completely missing until now. Note that the implementation of ::union() is identical to that in HEAD!

Test results for the commit prior to that one:

Testing Drupal\Tests\ckeditor5\Unit\HTMLRestrictionsTest
.......................F...F........F.....F..................     61 / 61 (100%)

Time: 00:00.038, Memory: 6.00 MB

There were 4 failures:

Tests results for that commit:

Testing Drupal\Tests\ckeditor5\Unit\HTMLRestrictionsTest
.......................F...F........F.....F.....................E 65 / 81 ( 80%)
EEEE....FF....EE                                                  81 / 81 (100%)

Time: 00:00.045, Memory: 6.00 MB

There were 7 errors:

So … that indicates there were multiple bugs in HEAD that this issue is fixing! (Now removing the Needs tests tag — I will continue adding more test coverage, but at this point I think I've proven beyond a doubt that there are a number of bugs that this issue is solving. 👍)

73ac5784956f5b777c2c29510130fe1433e2568f should fix those failures.

Wim Leers’s picture

3 of the 4 remaining failures (yes that "1 fail" is actually four … blame DrupalCI) should be fixed in https://git.drupalcode.org/project/drupal/-/merge_requests/1628/diffs?co...

  1. 1) Drupal\Tests\ckeditor5\Unit\HTMLRestrictionsTest::testParse with data set "tag with wildcard attribute" ('', array(true))
    Failed asserting that two arrays are identical.
    --- Expected
    +++ Actual
    @@ @@
     Array &0 (
    -    'a' => true
    +    'a' => false
     )
    
  2. 2) Drupal\Tests\ckeditor5\Unit\HTMLRestrictionsTest::testParse with data set "tag with single attribute allowing multiple specific values (reverse order)" ('', array(array(array(true, true))))
    Failed asserting that two arrays are identical.
    --- Expected
    +++ Actual
    @@ @@
     Array &0 (
         'a' => Array &1 (
             'target' => Array &2 (
    +            '_blank' => true
                 '_self' => true
    -            '_blank' => true
             )
         )
     )
  3. 3) Drupal\Tests\ckeditor5\Unit\HTMLRestrictionsTest::testRepresentations with data set "realistic" (Drupal\ckeditor5\HTMLRestrictions Object (...), array('', '', ''), '  ', array(array('a', array(true, array('en', 'fr'))), array('p', array(true)), array('br')))
    assert($value === TRUE || Inspector::assertAllStrings($value)) in /var/www/html/core/modules/ckeditor5/src/HTMLRestrictions.php:498
    
Wim Leers’s picture

Title: Refactor HTMLRestrictionsUtilities to a HtmlRestrictions value object » [PP-1] Refactor HTMLRestrictionsUtilities to a HtmlRestrictions value object
Related issues: +#3259174: Add missing CKE5 SmartDefaultSettings test coverage (wildcard tag with unsupported attribute)

4f07de09 passed testing. 😱 That means that the last caller of any HTMLRestrictionsUtilities code is in a section of SmartDefaultSettings with zero test coverage.

So, to be able to proceed, we need test coverage that tests that untested code path, which should then trigger a test failure. I'll add that here, but it really should not land in this MR — that makes this MR too unwieldy to review. Opened #3259174: Add missing CKE5 SmartDefaultSettings test coverage (wildcard tag with unsupported attribute) for that.

Wim Leers’s picture

Wim Leers’s picture

Yay, that resulted in the failure we hoped:

There was 1 failure:

1) Drupal\Tests\ckeditor5\Kernel\SmartDefaultSettingsTest::test with data set "basic_html_with_alignable_p can be switched to CKEditor 5 without problems, align buttons added automatically" ('basic_html_with_alignable_p', array(), array(array(array('bold', 'italic', '|', 'link', '|', 'bulletedList', 'numberedList', '|', 'blockQuote', 'uploadImage', '|', 'heading', '|', 'sourceEditing', '|', 'code', 'textPartLanguage', 'alignment', 'alignment:left', 'alignment:center', 'alignment:right', 'alignment:justify')), array(array(array('', '', '', '', '', '', '', '', '', '', '', '', '')), array(array('heading2', 'heading3', 'heading4', 'heading5', 'heading6')), array('un'))), '

👍
tim.plunkett’s picture

Title: [PP-1] Refactor HTMLRestrictionsUtilities to a HtmlRestrictions value object » Refactor HTMLRestrictionsUtilities to a HtmlRestrictions value object

Both blockers have been committed!

Wim Leers’s picture

Wonderful! Just pushed a rebased branch. The following 3 commits are now omitted from the branch thanks to those issues landing:

  1. https://git.drupalcode.org/project/drupal/-/merge_requests/1628/diffs?co...
  2. https://git.drupalcode.org/project/drupal/-/merge_requests/1628/diffs?co...
  3. https://git.drupalcode.org/project/drupal/-/merge_requests/1628/diffs?co...

That should trigger some new failures, because more bugs will now be exposed. In particular, the data structure validation added to the constructor (in validateAllowedRestrictionsPhase4()) should detect that there is a problem with the computed union for wildcard tags (<$block>).

It is no coincidence that wildcard handling also is the very last remaining thing for which SmartDefaultSettings is calling HTMLRestrictionsUtilities. I already have extra explicit test coverage locally that I will push tomorrow, as well as progress on fixes for those.

More tomorrow!

Wim Leers’s picture

That should trigger some new failures, because more bugs will now be exposed. In particular, the data structure validation added to the constructor (in validateAllowedRestrictionsPhase4()) should detect that there is a problem with the computed union for wildcard tags (<$block>).

That happened 🥳 This is the error that is causing all test failures:

The "$block" HTML tag has attribute restriction "class", but it is not an array of key-value pairs, with HTML tag attribute values as keys and TRUE as values.

… but there is no unit test yet showing what the root cause. The root cause is that the computed union (of all elements supported by all available CKEditor 5 plugins) is not correct. This is also broken in HEAD but the absence of validation makes it impossible to see.

So, just pushed https://git.drupalcode.org/project/drupal/-/merge_requests/1628/diffs?co... which adds a unit test that makes that easy to see 👍

Wim Leers’s picture

"Not currently mergeable" → due to #3248177: Language toolbar item cannot be removed from the toolbar just having landed half an hour ago, this resulted in a simple conflict. Rebased!

Wim Leers’s picture

Alright, as promised in #35: pushed wildcard test cases for ::union() that reproduced the failure. Then started to apply the same wildcard test cases to ::diff() and ::union(). I realized I was doing a lot of copy/pasting … and so I refactored that into a single test method that tests all 3 operations, and a single data provider that has a lot of:

    yield 'attribute restrictions are different: <a hreflang="en"> vs <a hreflang="fr">' => [
      'a' => new HTMLRestrictions(['a' => ['hreflang' => ['en' => TRUE]]]),
      'b' => new HTMLRestrictions(['a' => ['hreflang' => ['fr' => TRUE]]]),
      'diff' => 'a',
      'intersection' => new HTMLRestrictions(['a' => FALSE]),
      'union' => new HTMLRestrictions(['a' => ['hreflang' => ['en' => TRUE, 'fr' => TRUE]]]),
    ];

test cases in its data provider. This ensures that every operation has the exact same test coverage (I had made mistakes in my copy/pasting before! 😬), and also shows very clearly how different operations have different effects. Also, I added the ability to not copy/paste needlessly: instead of a HtmlRestrictions object as an expectation, you can also specify 'a' or 'b' — meaning the result of a→operation(b) is … exactly operand a or operand b. This makes the test coverage a lot more maintainable.

Next up: making all those tests actually pass!

Wim Leers’s picture

We went from

Testing Drupal\Tests\ckeditor5\Unit\HTMLRestrictionsTest
................................................................. 65 / 88 ( 73%)
.....FF..FF..........EE                                           88 / 88 (100%)

Time: 00:00.047, Memory: 6.00 MB
<snip>
Testing Drupal\Tests\ckeditor5\Kernel\SmartDefaultSettingsTest
EEEEEE.E..                                                        10 / 10 (100%)

Time: 00:07.687, Memory: 6.00 MB

to the commit that fixed ::union() getting us to:

Testing Drupal\Tests\ckeditor5\Unit\HTMLRestrictionsTest
................................................................. 65 / 88 ( 73%)
.....FF..FF............                                           88 / 88 (100%)

Time: 00:00.047, Memory: 6.00 MB

… and no other failures 😄

Now the commit fixing ::diff() and ::intersect() should get us to 100% green again. 🤞

Once that has happened, I can refactor away the last use of \Drupal\ckeditor5\HTMLRestrictionsUtilities::getWildcardTags() from SmartDefaultSettings like I said yesterday in #34 … 🤓🥳

Wim Leers’s picture

Assigned: Wim Leers » Unassigned
Status: Needs work » Needs review

VICTORY: https://git.drupalcode.org/project/drupal/-/merge_requests/1628/diffs?co... → this was the last use of HTMLRestrictionsUtilities.

#3259174: Add missing CKE5 SmartDefaultSettings test coverage (wildcard tag with unsupported attribute) added test coverage to HEAD for this piece of code. Now it is drastically simplified, thanks to the new HTMLRestrictions value object having ::diff(), ::intersect() and ::union() operators. That means that individual pieces of code no longer need to have complex logic (in this case: eight levels of nested if and for statements!!!!!) to interpret/compare \Drupal\filter\Plugin\FilterInterface::getHTMLRestrictions() arrays! 🥳

Note that I’m only doing minimal simplification here — the goal here is to refactor HTMLRestrictionsUtilities away, not to refactor SmartDefaultSettings. So I’m resisting that temptation, to land this as soon as possible.

In the commit linked above, you can see ~60 lines of complex code disappear. The complexity is now in those 3 operations. We just use those operations. And those operations are very thoroughly unit-tested. Therefore fixing any edge cases that I might have missed will be orders of magnitude simpler the next time 😊

Note that this merge request only handles the allowed top-level key of \Drupal\filter\Plugin\FilterInterface::getHTMLRestrictions()forbidden_tags is currently ignored. But that is no regression compared to HEAD anyway. #3231336: Simplify HtmlRestrictions and FundamentalCompatibilityConstraintValidator now that "forbidden tags" are deprecated will have to add support for that. We could do it here too, but then the scope will become even bigger.

Note that if you look at the total set of changes at https://git.drupalcode.org/project/drupal/-/merge_requests/1628/diffs, then you’ll notice that every file sees a net reduction in lines of code — with the exception of the new value object’s class and its test coverage of course. There’s a net increase of ~1000 lines of code. But ~700 of those are for test coverage! Much of the remaining 300 is due to additional comments.
(And again, note that SmartDefaultSettings will be able to get simplified further, but I consider that out of scope here.)

Follow-ups that will be unblocked once this lands:

I'll push a few clean-up commits tomorrow, but this is fundamentally ready for review. I'd be happy to walk reviewers through the changes in a call! 🤓

Wim Leers’s picture

Since my last comment:

  1. Addressed @bnjmnm's feedback
  2. Finished test coverage for HTMLRestrictions
  3. Ensured we pave the path instead of putting roadblocks up for #3231334: Global attributes (<* lang> and <* dir="ltr rtl">): validation + support (fix data loss): b31e98a8 fixes an oversight I made in 739d10b
  4. Updated FundamentalCompatibilityConstraintValidator to use the new value object operations instead of custom array logic in 39c99b2f + de2a1b57
  5. Updated SmartDefaultSettings to use the new value object operations instead of custom array logic in f9956225 + 5603a62c
Wim Leers’s picture

Walked @bnjmnm through most of the commit history starting at the beginning and going all the way to https://git.drupalcode.org/project/drupal/-/merge_requests/1628/diffs?co.... Things made sense to him so far. He made 3 great suggestions:

  1. rename ::parse() to ::fromString(), for symmetry with ::fromFilterPluginInstance() and ::fromTextFormat()
  2. for the diff and intersection set operations, one piece is tricky at first sight, but trivial once you realize that the validation of the array structure in the constructor provides allows one to make assumptions about the array structure — a simple @see makes that very clear
  3. rename ::union() to ::merge(), because A) ::union() sounded unfamiliar and ::merge() does not (because array_merge()), B) "union" is not actually a verb/action, and "diff" and "intersect" are, but "unionize" … means something entirely different :P
bnjmnm’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
120.04 KB

Whoa!

HTML restrictions are represented in several different ways depending on where they are being processed - Strings of HTML with special wildcard characters, HTML Filter config arrays, CKEditor 5 allowed tags config (that support different wildcard characters), and CKEditor 5 GHS config. These various formats need to be compared and combined - the process for doing this was distributed across multiple classes. They might be stored as a string, inside a text format, or an object such as a plugin defintion. This centralizes these representations/locations into a single object and that normalizes for comparison/combining. The HTMLRestrictions constructor accepts every possible representation and is able to be compared/combined with any other HTMLRestrictions object, regardless of how it was constructed.

@Wim Leers walked me through the entire MR. Despite the size of the diff, this is largely repackaging logic that already existed in CKEditor 5 in a manner that makes it easier to test, then improving that logic based on new tests that failed. Many of the use cases that surfaced were due to PHP's array intersect/merge etc. functions being insufficient because HTMLRestrictions config for tags and attributes can be an array or a boolean values.

Attached patch in case we've reached "needs rebase" fatigue.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 43: 3248469-40-94x.patch, failed testing. View results

lauriii’s picture

Status: Needs work » Reviewed & tested by the community

Moving back to RTBC due to random failure in a test case that is known for random test failures.

Wim Leers’s picture

FYI:

1711 insertions, 511 deletions.

→ this breaks down into:

  • 866 new lines in the new \Drupal\ckeditor5\HTMLRestrictions
  • … minus the 284 lines of the old and now deleted \Drupal\ckeditor5\HTMLRestrictionsUtilities
  • 730 new lines in the new \Drupal\Tests\ckeditor5\Unit\HTMLRestrictionsTest
  • all files that previously used something from HTMLRestrictionsUtilities have stayed equally big (2 files), or became smaller (7 files), and their logic always became simpler.
larowlan’s picture

Hiding patches because there's an MR

larowlan’s picture

Status: Reviewed & tested by the community » Needs review

Great work, left a review.

Love how much cleaner consuming code is with this patch.

Moving back to NR because there's a few unresolved items from both myself and @lauriii

Wim Leers’s picture

Addressed all of @lauriii's feedback. Implicitly addresses some of @larowlan. Will do Lee's tomorrow :)

Wim Leers’s picture

Now also addressed all of @larowlan's feedback.

P.S.: it took four minutes for this to even begin queueing a test run 🤯 Also, all those "this line changed in version X of the diff" auto-comments are useless in the context of the d.o issue, because the parent context is not displayed. So much distraction on this issue 😔

Wim Leers’s picture

Patch to make this committable to 9.3, 9.4 and 10.0.

lauriii’s picture

Status: Needs review » Reviewed & tested by the community

Thank you! The MR looks good for me now. All feedback has been resolved with the exception of one comment where I wasn't fully sure if it has been addressed: https://git.drupalcode.org/project/drupal/-/merge_requests/1628#note_69392. Asked @Wim Leers about that and he said he is 99% certain that he has been able to address the feedback from @larowlan. Based on that, moving to RTBC.

Wim Leers’s picture

Yep, that specific comment by @larowlan was also addressed. I just didn't mark it resolved to give @larowlan the opportunity to provide feedback, since that was the only non-trivial change in response to his feedback 😊🤓

Wim Leers’s picture

Apparently 9.3.x differs from 9.4.x in nits — $ git diff origin/9.3.x origin/9.4.x -- core/modules/ckeditor5/src/Plugin/Validation/Constraint/FundamentalCompatibilityConstraint* core/modules/ckeditor5/src/Plugin/Validation/Constraint/SourceEd* yields 9.3-differences.txt.

git apply -3 handles these graciously. patch -p1 does not.

Uploading a patch-compatible 9.3.x patch. Re-uploading the patch in #51 to make it clear it's targeted for both 9.4.x and 10.0.x. Also uploading diff-between-patches.txt to show the actual differences between these two huge patches: it's caused entirely by 9.3-differences.txt!

bnjmnm’s picture

I'm prepared to commit this after the code freeze.

While it's certainly possible there are a few unturned stones in this giant MR, I see no evidence of anything that would have adverse impact. A few nits might still be hiding amongst the ~2000 changed lines of code. Were these to exist, they would be overshadowed by the substantial improvements provided here. Between @Wim Leers providing me a guided tour via Zoom, hours spent combing and Xdebugging this code, and most importantly the thorough + perceptive reviews from @lauriii and @larowlan, this strikes me as ready for commit. I'll be on the lookout for the thaw.

  • bnjmnm committed 2076524 on 10.0.x
    Issue #3228334 by Wim Leers, larowlan, lauriii, DieterHolvoet,...

  • bnjmnm committed cd4d856 on 9.4.x
    Issue #3228334 by Wim Leers, larowlan, lauriii, DieterHolvoet,...
bnjmnm’s picture

Status: Reviewed & tested by the community » Fixed

This beast is in!

Patch applied to 10.0.x, then cherry-picked to 9.4.x. Applied the 9.3.x patch (with its adorable differences) to 9.3.x since CKEditor 5 is experimental and the only user facing changes are objective improvements in how the allowed html tags field generates its value.

  • bnjmnm committed 97033f5 on 9.3.x
    Issue #3228334 by Wim Leers, larowlan, lauriii, DieterHolvoet,...

Status: Fixed » Closed (fixed)

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

aitala’s picture

FileSize
9.01 KB

The change to FilterHtml.php from 9.36 to 9.37 took down my Drupal site... When I replaced FilterHtml.php with the previous version, the site came back up.

The change in 9.37 was:

        // This tag has a notation like "<foo *>", to indicate all attributes
        // are allowed.
        if ($node->hasAttribute($star_protector)) {
          $restrictions['allowed'][$tag] = TRUE;
          continue;
        }

I've attached the error that was dumped...

Thanks,
Eric

aitala’s picture

deleted

Wim Leers’s picture

@aitala: woah! Can you share your exact filter_html configuration, or alternatively drush cget filter.format.YOUR_TEXT_FORMAT? That way I can try to reproduce the bug. I don't yet see how it's possible that this change caused breakage for you, but I take it very seriously! If you could provide me that info, I promise to dig into it immediately.

aitala’s picture

FileSize
9.7 KB

Here is an export of my text formats. I think review_html.yml may be the one to look at

Eric

acbramley’s picture

This broke our site as well. It will happen if any tag has a * for attributes. E.g I have <drupal-entity * data-*>(obviously this looks like semi broken config but it shouldn't cause a Fatal).

What happens is the code mentioned in #62 sets the allowed tags to TRUE, then in filterAttributes we have the following code:

      if ($tag_attributes === FALSE) {
        $tag_attributes = [];
      }
      $allowed_attributes = ['exact' => [], 'prefix' => []];
      foreach (($global_allowed_attributes + $tag_attributes) as $name => $values) {

At this point $tag_attributes is TRUE and therefore we get an error in the foreach

TypeError: Unsupported operand types: array + bool in Drupal\filter\Plugin\Filter\FilterHtml->filterAttributes() (line 122 of core/modules/filter/src/Plugin/Filter/FilterHtml.php). 

EDIT: Created #3268983: [regression] FilterHtml throws Unsupported operand types error when * used in tag attribute

pingers’s picture

Thanks for posting @acbramley - also experiencing the same issue with our sites D9 sites because of <{some element} *>

plach’s picture

This bit us as well, I just posted a mitigation patch at #3268983-8: [regression] FilterHtml throws Unsupported operand types error when * used in tag attribute in case anyone needs it.