[6.x] Inline styles (alignment, font color, background color) are stripped on save
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
Hướng nghiên cứu
Bắt đầu từ Field::createHtmlSanitizer() trong lớp field của CKEditor, nơi các lệnh gọi allowAttribute('style', ...) được thực hiện một lần cho mỗi nút danh sách, và mỗi lệnh gọi xóa style khỏi các phần tử nằm ngoài danh sách của nó. Tái hiện bằng cách chạy sanitizer trên <p style="text-align:center">a</p> và <span style="color:#ff0000;">x</span>. Hoàn thành khi các inline style đó được giữ lại, style được cho phép trên p, h1-h6, div, span, ol, ul và li trong một lệnh gọi duy nhất, và hành vi của sanitizer được bao phủ bởi một bài kiểm thử.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- PHP
- Star
- 47
- Fork
- 35
- Merge trung bình
- 1 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 25
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của craftcms/ckeditor
-
repo:ckeditor
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
craftcms/ckeditor#682 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
repo:ckeditor
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 52/100
craftcms/ckeditor#678 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug repo:ckeditor
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 40/100
craftcms/ckeditor#665 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[6.x]: Esc in a fullscreen CKEditor field closes Preview instead of leaving fullscreenCó thể đã có người làm @i-just đã nhận 15 ngày trước. Đang mởbug repo:ckeditor
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 58/100
craftcms/ckeditor#651 · 3 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug repo:ckeditor
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 54/100
craftcms/ckeditor#646 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của craftcms/ckeditor
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Codeinwp/optimole-wp#1259 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
component/core domain/framework
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100