Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
While working on #3222797: Upgrade path from CKEditor 4's StylesCombo to CKEditor 5's Style, I noticed that, given $a = HTMLRestrictions::fromString('<tag attr="A B">');
and $b = HTMLRestrictions::fromString('<tag attr>');
, this happens:
- ✅
$b->diff($a)
results in['tag' => ['attr' => TRUE]]
, which is correct:$a
does not allow everything$b
allows - ❌
$a->diff($b)->getAllowedElements()
results in['tag' => ['attr' => ['A', 'B']]
, but should be[]
— since$b
allows a superset of$a
Steps to reproduce
See above.
Proposed resolution
Fix this.
Remaining tasks
N/A
User interface changes
N/A
API changes
None.
Data model changes
None.
Release notes snippet
N/A
Comment | File | Size | Author |
---|---|---|---|
#9 | 3278394-9.patch | 7.75 KB | Wim Leers |
#9 | interdiff.txt | 2.5 KB | Wim Leers |
#7 | 3278394-7.patch | 6.55 KB | Wim Leers |
|
Issue fork drupal-3278394
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:
Comments
Comment #3
Wim LeersFor test coverage: I could add a test to
HTMLRestrictionsTest
like:… but that would be silly because we already have the massive
\Drupal\Tests\ckeditor5\Unit\HTMLRestrictionsTest::testOperations()
with an enormous data provider.Turns out there's a wrong expectation in the expectations, and that's how we missed this bug! Fixed test expectation in ed4a73cd3fea1b2b0598803d0be4ae895239b22a.
Comment #4
Wim LeersNow ready for review!
Comment #5
Wim LeersUh oh — I fixed
\Drupal\Tests\ckeditor5\Unit\HTMLRestrictionsTest::testOperations()
but broke two other tests 😅Comment #6
Wim LeersNow the only remaining failure is this:
Mysterious, right? 🤓🙈
Let's unravel it. 🕵️
diff()
now correctly handles an extra case. In the failing test, the desire is to support<foo bar>
(meaning ANY value on thebar
attribute on thefoo
tag), buttest_attr_values
only supports<foo bar="a b">
. In other words: there is no surplus at all here. With the fix in this issue, that changes the score to0
instead of1002
. The score used to be 1002 (meaning "two surplus attribute values" and "one surplus attribute") because<foo bar="a b"> DIFF <foo bar> === <foo bar="a b">
in HEAD, but we're fixing that to be<foo bar="a b"> DIFF <foo bar> = ∅
, which completely explains that difference in score.In other words: this is another example of something that was wrong in the test expectations!
Fixed in 3af97b37934a63f4f29bf0fd8acd4bb2c115995e.
Comment #7
Wim Leers6aa08d5fc as patch, to test against all
34 branches.Comment #8
bnjmnmThis is basically RTBC but a committer would need to make a small change on commit. If the committer reading this would prefer to not take on that responsibility, feel free to switch back to NW.
The small change that is needed:
Suffix would be `*-bar` 🤓
Comment #9
Wim Leers#8 OMG 🤣 🙈
Fixed! 😁 (This is a pre-existing bug, but totally reasonable to fix here IMHO. Which is why the patch size grew a bit: there were three places within the same file which contained this comment bug.)
Comment #11
Wim LeersRandom unrelated Layout Builder test fail. Re-testing.
Comment #14
lauriiiCommitted ce0ec61 and pushed to 10.0.x. Cherry-picked to 9.5.x and 9.4.x. Thanks!
Leaving open for backport to 9.3.x once freeze is over.
Comment #16
larowlanUpdating status
Comment #17
Wim LeersNot yet backported 😅
Comment #18
alexpottBackported to 9.3.x as this is experimental there and there is no harm