[6.x] Inline styles (alignment, font color, background color) are stripped on save
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 78/100
調査の方向性
CKEditor のフィールドクラスにある Field::createHtmlSanitizer() から始めてください。ここでは allowAttribute('style', ...) の呼び出しがリストボタンごとに一度ずつ行われ、各呼び出しがそのリスト外の要素から style を削除しています。<p style="text-align:center">a</p> と <span style="color:#ff0000;">x</span> に対してサニタイザーを実行して再現してください。インラインスタイルが残り、単一の呼び出しで p、h1-h6、div、span、ol、ul、li に style が許可され、サニタイザーの動作がテストで網羅されていれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Description
In 6.0.0-beta.2, anything the editor stores as an inline style attribute is removed when the field is saved. Text alignment, font color and font background color all revert after saving.
Two causes in Field::createHtmlSanitizer():
allowAttribute('style', …)is called up to three times (['div', 'span'], then['ol']whennumberedListis in the toolbar, then['ul']whenbulletedListis). Symfony'sHtmlSanitizerConfig::allowAttribute()removes the attribute from every element not in the list it is given, so each call undoes the previous one. With both list buttons enabled,styleis only allowed on<ul>.styleis never allowed on block elements (p,h1–h6, …), so thealignmenttoolbar item can't persisttext-aligneven without the list buttons.
Steps to reproduce
- Create a CKEditor field with
alignment,fontColor,bulletedListandnumberedListin the toolbar, with "Sanitize HTML" on and the default sanitizer. - Center a paragraph and give some text a font color.
- Save the entry.
Expected behavior
The alignment and color are kept, as in 5.x.
Actual behavior
Both are gone after saving. Running the field's sanitizer directly:
<p style="text-align:center">a</p> => <p>a</p>
<span style="color:#ff0000;">x</span> => <span>x</span>
Workaround
Listening for HtmlSanitizerConfigResolving and re-allowing style on the affected elements in a single call:
Event::listen(function (HtmlSanitizerConfigResolving $event): void {
$event->config = $event->config->allowAttribute('style', [
'div', 'span', 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'ol', 'ul', 'li',
]);
});
Versions
- craftcms/ckeditor 6.0.0-beta.2 (same code on the current
6.xbranch) - craftcms/cms 6.0.0-beta.2
- symfony/html-sanitizer 8.1.12
- PHP 8.5.5
- 主要言語
- PHP
- スター
- 47
- フォーク
- 35
- 平均マージ
- 1日 2時間
- マージ済み PR(30日)
- 25
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
craftcms/ckeditor のほかの issue
-
repo:ckeditor
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
craftcms/ckeditor#682 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
repo:ckeditor
難易度 3/5 1〜2日 初心者へのやさしさ 52/100
craftcms/ckeditor#678 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug repo:ckeditor
難易度 3/5 1〜2日 初心者へのやさしさ 40/100
craftcms/ckeditor#665 · コメント 2 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
[6.x]: Esc in a fullscreen CKEditor field closes Preview instead of leaving fullscreen対応中かも @i-just が 15 日前に担当しました。 オープンbug repo:ckeditor
難易度 3/5 1〜2日 初心者へのやさしさ 58/100
craftcms/ckeditor#651 · コメント 3 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
bug repo:ckeditor
難易度 3/5 1〜2日 初心者へのやさしさ 54/100
craftcms/ckeditor#646 · コメント 2 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
craftcms/ckeditor の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Codeinwp/optimole-wp#1259 ·
メンテナーはふだん 1 日以内に返信
-
component/core domain/framework
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 75/100