Problem/Motivation
Depends on #3228334: Refactor HTMLRestrictionsUtilities to a HtmlRestrictions value object.
If a text format has partial wildcard attributes, especially data-*, the upgrade path currently will not work correctly.
This will fail in the upgrade path (i.e. will configure the "Source Editing" plugin incorrectly), but likely also fails to configure CKE5 GHS correctly: this goes further than what #3259493: [GHS] Unable to limit attribute values: ::allowedElementsStringToHtmlSupportConfig() does not generate configuration that CKEditor 5 expects fixes.
Related, but on the JS side of making data-* support happen: #3227822: [GHS] Ensure GHS works with our custom plugins, to allow adding additional attributes.
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #36 | 3260853-36.patch | 27.88 KB | wim leers |
| #31 | 3260853-31.patch | 27.88 KB | bnjmnm |
| #21 | 3260853-29-9-and-10.patch | 19.7 KB | bnjmnm |
| #5 | 3260853-5_on_top_of_3228334-41.patch | 123.27 KB | wim leers |
| #5 | 3260853-5-do-not-test.patch | 8.78 KB | wim leers |
Issue fork drupal-3260853
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 #2
wim leersThis will result in:
and:
Comment #3
wim leersTangentially related CKEditor 4/filter system issue: #2105841: Xss filter() mangles image captions and title/alt/data attributes.
Comment #4
wim leersComment #5
wim leers#4 already added some parsing/representation tests, but this adds the crucial tests for the
SmartDefaultSettingstest to actually pass: a failing test for the various operations onHtmlRestrictions.Comment #8
wim leers#3228334: Refactor HTMLRestrictionsUtilities to a HtmlRestrictions value object is in! Now really pushing this forward again…
Comment #10
wim leersComment #11
lauriiiDo you think it would be easy for us to re-use the integration test coverage from #3259493: [GHS] Unable to limit attribute values: ::allowedElementsStringToHtmlSupportConfig() does not generate configuration that CKEditor 5 expects here?
Comment #12
wim leersYes, definitely!
Want to postpone this on that then?
Comment #13
lauriiiLet's do that. Postponed until test coverage from #3259493: [GHS] Unable to limit attribute values: ::allowedElementsStringToHtmlSupportConfig() does not generate configuration that CKEditor 5 expects has been committed.
Comment #14
wim leersActually, that's a very good call, because that will ensure it actually works in CKEditor 5, because I think it currently does not … 🙈 And the fix that makes that super easy to add is also in #3259493: [GHS] Unable to limit attribute values: ::allowedElementsStringToHtmlSupportConfig() does not generate configuration that CKEditor 5 expects!
Comment #15
wim leers#3259493: [GHS] Unable to limit attribute values: ::allowedElementsStringToHtmlSupportConfig() does not generate configuration that CKEditor 5 expects is in!
Comment #16
wim leersFunctional JS tests now added. In doing that, I realized that the issue title was not complete enough yet.
Comment #17
wim leersYou can now go crazy with configurations like
in your
Source Editingconfiguration! 🤓🥳I had to change
\Drupal\ckeditor5\HTMLRestrictions::toGeneralHtmlSupportConfig()to use the key/value syntax documented at https://ckeditor5.github.io/docs/nightly/ckeditor5/latest/api/module_eng..., which is not listed at https://ckeditor5.github.io/docs/nightly/ckeditor5/latest/features/gener....Note that we do have functional JS test coverage for this now — see
→ that's a wildcard attribute name that has wildcard attribute values allowed! And we verify that CKEditor 5 in fact makes it possible to create this kind of content, only when it is configured to allow that!
Comment #19
bnjmnmPretty minor stuff in my review, but setting to NW for visiblity.
Comment #20
wim leersGreat feedback, thanks @bnjmnm, for your very thorough reviews! 👏
Comment #21
bnjmnmAll my feedback is addressed, and the HTMLRestrictions object grows more powerful.
Comment #22
wim leersThanks!
I queued a D10/PHP8.1 test. It only failed on D10 because it was using PHP 8.0, which D10 no longer supports as of last week 🥸
Comment #23
lauriiiI don't fully understand how is supporting
data-*sufficient for the upgrade path. It seems like that's the only use case that has explicitly test coverage. However, it seems like other use cases are supported regardless of that. Also based on documentation for\Drupal\filter\Plugin\FilterInterface::getHTMLRestrictions,data-*isn't the only supported use case. 🤔Comment #24
wim leers#23:
data-*is the common case, and probably >95% of all "wildcard attribute name" uses in Drupal 8. This issue focuses on that, to allow more sites to successfully switch to CKEditor 5 ASAP. But you're right that this either needs a follow-up or we need to expand this issue's scope.Do you have a preference?
Comment #25
lauriiiI'm fine with having a stable blocking follow-up issue. I was just confused because I got a sense from this issue, that this would be the only supported wildcard use case.
Comment #26
wim leersSpent the past hour digging into #23–#25.
Turns out that doing this is relatively straightforward, so let's get this done here and now! This is pushing WAY beyond what was ever possible in CKEditor 4 🤯🤩🚀
(It's really cool to see even these pretty complex wildcard attribute restrictions appear correctly in the
FilterHtmlconfiguration, and not just that, but know that it is correctly interpreted everywhere 😊)Comment #27
wim leersUpdating issue title to clarify that.
Comment #28
wim leers15f3fdd9b54618c34bd76ae18a0bfbe441c5bd21added explicit test coverage — most notably it generalizes/parametrizes thedata-*operations test coverage, so we can not only test suffix wildcards (i.e.data-*), but also prefix*-fooand infixfoo-*-bar). The functional JS test coverage is also updated to test infix + prefix instead of only suffix.This should FAIL.
878727479c0eb29f4eca56133d63f427f576edf0adds support for arbitrary suffix (so not justdata-*, butANYTHING*) and then expands it to also support prefix and infix wildcards.c534af6a67e7eb305df6e7e03035580bee8a8115is a small addition that #3228334: Refactor HTMLRestrictionsUtilities to a HtmlRestrictions value object overlooked:new HTMLRestrictions(['foo' => ['*' => TRUE]])does not make sense, one should usenew HTMLRestrictions(['foo' => TRUE])in that case. I realized this while working on the 2 preceding commits, and it allows me adding a clear assertion to::isWildcardAttributeName().Comment #29
bnjmnmDifferent wildcard locations didn't require that much to be changed, nice!
Found a few things that should be fairly easy to address, threads in MR.
Comment #30
wim leersSolid remarks — even though I tried to carefully reword/rephrase existing docs, I clearly didn't do a good enough job 😔 Thanks for paying attention to the important details :)
Comment #31
bnjmnmComment #32
bnjmnmIt looks like both my and @lauriii's feedback has been addressed.
Comment #33
wim leersThanks @bnjmnm!
Even though this is RTBC, there's some failures here. But … they're all actually to be ignored 😄
AjaxBlockTest, 100% unrelated.Comment #34
lauriiiGreat work here 👏
Should we use
static::getRegExForWildCardAttributeName()here?Comment #35
wim leersUnrelated random
AjaxBlockTestfailures in 9.3 and 10 😬#34: implemented — great catch! Note that we can only replace the second line you quoted, the first is subtly different because it handles attribute values, not attribute names.
Comment #36
wim leersComment #39
lauriiiCommitted 359a11a and pushed to 10.0.x. Cherry-picked to 9.4.x. Thanks!
Leaving open for 9.3.x cherry-pick once the freeze is over.
Comment #41
bnjmnmCherry-picked to 9.3.x now that freeze is over.