Problem/Motivation
- Merging
- ✅ Merging
<a hreflang>and<a hreflang="en">works fine. - ✅ Merging
<ol type>and<ol type="A">works fine. - ❌ Merging
<ol type>and<ol type="1">CRASHES. - GHS representation
Why?
Because https://3v4l.org/fVk1K.
Related: HtmlRestrictions::fromString('<ol type="1">')->toGeneralHtmlSupportConfig() fails with:
assert($value === TRUE || Inspector::assertAllStrings($value)) in core/modules/ckeditor5/src/HTMLRestrictions.php:1018
because its assumptions are incorrect, again because of https://3v4l.org/fVk1K.
Steps to reproduce
See #3261599-7: Use CKEditor 5's native <ol start> support (and also support <ol reversed>).
Proposed resolution
TBD
Remaining tasks
- Tests.
- Fix.
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #24 | interdiff-22-24.txt | 2.34 KB | nod_ |
| #24 | core-html-3274648-24.patch | 11.99 KB | nod_ |
| #22 | core-html-3274648-22.patch | 11.96 KB | nod_ |
| #21 | interdiff-19-21.txt | 6.94 KB | nod_ |
| #21 | core-html-3274648-21.patch | 11.96 KB | nod_ |
Comments
Comment #2
wim leersComment #3
wim leersActually, it's not just that. It's also
::toGeneralHtmlSupportConfig(). Adding test coverage for that too.Comment #5
wim leersAt least #3 is a trivial fix. The assertion is pointless and wrong, so we can just remove it.
Comment #9
nod_If I look at #3278394: HTMLRestrictions' diff operation bug: diff(<tag attr="A B">, <tag attr>) should return an empty result in those cases: diff should be
HTMLRestrictions::emptySet()no?Comment #10
wim leers#9: Woah … yes indeed … 😬 Great find! Sorry for misleading you there 🙈
Comment #11
nod_Messed around with RecursiveIteratorIterator and RecursiveArrayIterator to replace array_merge_recursive but couldn't make it work like I want to. Anyway the fixed tests, still failing on merge as per the PHP issue.
Comment #12
wim leersToo bad! 😬
Comment #14
nod_Tried to go fancy when simple was enough. Many comments talk about strangeness of array_merge_recursive() so went for comparing the values directly instead of trying to infer what were the values based on the result.
the code style is pretty different than the other methods so might need some work, left most comments as-is so they're not accurate anymore. in any case it should be green.
Comment #16
nod_somehow that all pass locally :/
Comment #17
wim leersReproduced the failure locally on
9.5.xwith both PHP 7.4 and 8.0.Comment #18
wim leersAre you sure you have
zend.assertions=1in yourphp.ini?Comment #19
nod_Yep, it was the assertions config.
Comment #20
wim leersThis now blocks #3273983: Do not assume that plugin supporting <tag attr> also supports <tag> in SourceEditingRedundantTags and upgrade path, which is major and a stable blocker.
Review
As the author of the current
\Drupal\ckeditor5\HTMLRestrictions::merge()(after having adapted it from @bnjmnm's code, but sprinkled a lot of extra complexity on it): thank you, this is MUCH simpler! 🤩🙏Even the diffstat say this pretty objectively (when you exclude the new test cases and the DrupalCI changes to restrict to CKE5 tests only):
Two things:
A) this is stateless. So let's change this to
staticB) Drupal core does not use underscore-based naming in methods.
s/is/are/
s/needs/need/
Comment is outdated. Needs to be rewritten.
Comment is outdated. Can be deleted altogether I think 🥳
Comment #21
nod_updated docs
Comment #22
nod_phpcs
Comment #23
wim leersFinal review round — will RTBC next 🤓 🥳
"configuration array" vs "restriction array" vs "configuration elements"
Let's make these consistent.
This is referring to
\Drupal\filter\Plugin\FilterInterface::getHTMLRestrictions()'s "allowed elements".That's why
\Drupal\ckeditor5\HTMLRestrictions::$elementsis described as "An array of allowed elements."So I propose to call this
mergeAllowedElementsLevel(). Why "level"? Because it is able to recurse one time, because this processes one level: either the tags' attributes, or the attributes' attribute values.s/transform/transforms/
Comment #24
nod_Thanks for the pointers on docs :)
Comment #25
wim leersComment #27
nod_Comment #32
lauriiiCommitted 94b5d57 and pushed to 10.0.x. Cherry-picked to 9.5.x, 9.4.x and 9.3.x because this is a non-disruptive bug fix and CKEditor 5 is experimental. Thanks!
Comment #33
wim leersYay! This unblocked #3273983: Do not assume that plugin supporting <tag attr> also supports <tag> in SourceEditingRedundantTags and upgrade path and #3274635: [upstream] Use CKEditor 5's native <ol type> and <ul type> UX, plus it allowed me to close #3279470-7: HTMLRestrictions::merge() can crash due to array_merge_recursive() being affected by internal PHP array state 🥳