Comments

Wim Leers created an issue. See original summary.

wim leers’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new1.64 KB

Status: Needs review » Needs work

The last submitted patch, 2: 3278636-2.patch, failed testing. View results

nod_’s picture

Status: Needs work » Needs review
StatusFileSize
new3.47 KB

Fixed for tags, but it's still overwriting attributes config. The logic is very similar to #3274648: HTMLRestrictions::merge() and ::toGeneralHtmlSupportConfig() fail on allowed attribute values that can be interpreted as integers, spending a bit more time on it to make the code look nicer.

Status: Needs review » Needs work

The last submitted patch, 5: core-filterhtml-3278636-5.patch, failed testing. View results

nod_’s picture

Failure is because of a change in the order

nod_’s picture

So not an order problem. There is a problem in the SourceEditingPluginTest what we test for:

<foo1 bar-*>
<foo2 bar-*="baz">
<foo3 bar-*="baz qux-*">
<foo2 bar="baz-*">
<foo3 bar="baz qux-*">

What the expected result is:

<foo1 bar-*>
<foo2 bar="baz-*">
<foo3 bar="baz qux-*">

The test explicitly expect the duplicate declarations to be overwritten. So going to fix the test so that we expect:

<foo1 bar-*>
<foo2 bar-*="baz" bar="baz-*">
<foo3 bar-*="baz qux-*" bar="baz qux-*">
nod_’s picture

Status: Needs work » Needs review
StatusFileSize
new6.51 KB
new4.59 KB

Status: Needs review » Needs work

The last submitted patch, 9: core-filterhtml-3278636-9.patch, failed testing. View results

wim leers’s picture

#8: wow, great catch! 👍

Unrelated failure in ComposerHookTest::testComposerHooks(). Sounds like a recent 10.0.x regression. Queued test against 9.5.x.

+++ b/core/modules/filter/src/Plugin/Filter/FilterHtml.php
@@ -274,11 +281,21 @@ public function getHTMLRestrictions() {
+          // Mark the tag as allowed, assigning TRUE for each attribute name if
+          // all values are allowed, or an array of specific allowed values.
+          $restrictions['allowed'][$tag] = [];

This comment does not seem to match the logic? I think it was just moved, but not updated? 🤔

wim leers’s picture

#3283795: ComposerHooksTest is broken on latest DrupalCI PHP container fixed that (unrelated) fail on D10. Re-testing.

nod_’s picture

Status: Needs work » Needs review
StatusFileSize
new6.56 KB
new902 bytes

Comment seems ok to me, still makes sense. Added a little something that might make it clearer. Don't know how to make it better from here though.

wim leers’s picture

#13: the comment says it's marking TRUE, but it doesn't do that. I just realized the original location for this comment was similarly confusing though!

Further down, it says basically the same thing, but in the actual place where that does happen:

          if (empty($allowed_attribute_values)) {
            // If the value is the empty string all values are allowed.
            $restrictions['allowed'][$tag][$name] = TRUE;
          }
          else {
            // A non-empty attribute value is assigned, mark each of the
            // specified attribute values as allowed.
            foreach ($allowed_attribute_values as $value) {
              $restrictions['allowed'][$tag][$name][$value] = TRUE;
            }
          }

so I propose this, which I think would be clearer:

diff --git a/core/modules/filter/src/Plugin/Filter/FilterHtml.php b/core/modules/filter/src/Plugin/Filter/FilterHtml.php
index a044bd8a45..07a12b449d 100644
--- a/core/modules/filter/src/Plugin/Filter/FilterHtml.php
+++ b/core/modules/filter/src/Plugin/Filter/FilterHtml.php
@@ -281,12 +281,11 @@ public function getHTMLRestrictions() {
           continue;
         }
 
-        // If the same tag was present before in the configuration do not
-        // override existing contents.
+        // If the tag is not yet present, prepare to add attribute restrictions.
+        // Otherwise, check if a more restrictive configuration (FALSE, meaning
+        // no attributes were allowed) is present: then override the existing
+        // value to prepare to add attribute restrictions.
         if (!isset($restrictions['allowed'][$tag]) || $restrictions['allowed'][$tag] === FALSE) {
-          // When the tag did not exist previously, mark the tag as allowed,
-          // assigning TRUE for each attribute name if all values are allowed,
-          // or an array of specific allowed values.
           $restrictions['allowed'][$tag] = [];
         }
 
nod_’s picture

StatusFileSize
new6.54 KB
new1.06 KB

thanks :)

wim leers’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 15: core-filterhtml-3278636-15.patch, failed testing. View results

wim leers’s picture

Status: Needs work » Reviewed & tested by the community

Unrelated Layout Builder failure.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

The patch no longer applies.

mrinalini9’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new6.36 KB

Rerolled patch #15 for 10.0.x, please review it.

Status: Needs review » Needs work

The last submitted patch, 20: core-filterhtml-3278636-20.patch, failed testing. View results

nod_’s picture

Status: Needs work » Needs review
StatusFileSize
new6.34 KB
wim leers’s picture

Status: Needs review » Reviewed & tested by the community

🤩 Unit tests are green, I expect all tests to be green, so … 🚢

bnjmnm’s picture

Status: Reviewed & tested by the community » Needs work

There's a @todo mentioning this issue in Media.php

nod_’s picture

no idea what's supposed to happen in media.php, any idea wim?

wim leers’s picture

Great catch, @bnjmnm!

@nod: you're right that the comment is rather terse. It says that if this issue (#3278636) is fixed, we'll be able to update the Media plugin's PHP logic to not use HtmlRestrictions at all anymore. See #4.

So that means changing

    elements:
      - <drupal-media>
      - <drupal-media data-entity-type data-entity-uuid alt data-view-mode>

to

    elements:
      - <drupal-media>
      - <drupal-media data-entity-type data-entity-uuid alt>
      - <drupal-media data-view-mode>

in ckeditor5.ckeditor5.yml and

  public function getElementsSubset(): array {
    $all_elements = $this->getPluginDefinition()->getElements();
    $subset = HTMLRestrictions::fromString(implode($all_elements));
    $view_mode_override_enabled = $this->getConfiguration()['allow_view_mode_override'];
    if (!$view_mode_override_enabled) {
      $subset = $subset->diff(HTMLRestrictions::fromString('<drupal-media data-view-mode>'));
    }
    // @todo Simplify in https://www.drupal.org/project/drupal/issues/3278636, that will allow removing all uses of HTMLRestrictions in this class.
    return array_merge(['<drupal-media>'], $subset->toCKEditor5ElementsArray());
  }

to something far simpler, like:

  public function getElementsSubset(): array {
    $subset = $this->getPluginDefinition()->getElements();
    $view_mode_override_enabled = $this->getConfiguration()['allow_view_mode_override'];
    if (!$view_mode_override_enabled) {
      $subset = array_diff($subset, ['<drupal-media data-view-mode>']);
    }
    return $subset;
  }

(This is better, because it reduces the reliance on the technically private HtmlRestrictions in the CKEditor 5 plugin implementations that Drupal core contains. The bug that this issue is fixing prevented that!)

nod_’s picture

Status: Needs work » Needs review
StatusFileSize
new8.15 KB
new1.55 KB

yep, much simpler.

wim leers’s picture

Status: Needs review » Needs work
 19 | WARNING | [x] Unused use statement
nod_’s picture

Status: Needs work » Needs review
StatusFileSize
new8.42 KB
new535 bytes

Status: Needs review » Needs work

The last submitted patch, 29: core-filterhtml-3278636-29.patch, failed testing. View results

wim leers’s picture

Status: Needs work » Reviewed & tested by the community

Unrelated failure in Drupal\Tests\quickedit\FunctionalJavascript\LayoutBuilderQuickEditTest::testQuickEditIgnoresDuplicateFields().

RTBC, and re-testing.

wim leers’s picture

Priority: Minor » Normal
Issue tags: +DX (Developer Experience)

I don't think this is Minor at all, this can seriously hamper the DX, as the #27 interdiff proves.

alexpott’s picture

Version: 10.0.x-dev » 9.4.x-dev
Status: Reviewed & tested by the community » Fixed

Committed 4a16fbe and pushed to 9.4.x. Thanks!
Committed 51bd01d and pushed to 9.5.x. Thanks!
Committed 3682bd2 and pushed to 10.0.x. Thanks! >
Committed f7ef845 and pushed to 10.1.x. Thanks!

  • alexpott committed f7ef845 on 10.1.x
    Issue #3278636 by nod_, Wim Leers, mrinalini9, bnjmnm: HTMLRestrictions...

  • alexpott committed 3682bd2 on 10.0.x
    Issue #3278636 by nod_, Wim Leers, mrinalini9, bnjmnm: HTMLRestrictions...

  • alexpott committed 51bd01d on 9.5.x
    Issue #3278636 by nod_, Wim Leers, mrinalini9, bnjmnm: HTMLRestrictions...

  • alexpott committed 4a16fbe on 9.4.x
    Issue #3278636 by nod_, Wim Leers, mrinalini9, bnjmnm: HTMLRestrictions...

Status: Fixed » Closed (fixed)

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