[6.x] Inline styles (alignment, font color, background color) are stripped on save
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 78/100
Línea de trabajo
Empieza en Field::createHtmlSanitizer() en la clase de campo de CKEditor, donde las llamadas a allowAttribute('style', ...) se hacen una vez por cada botón de lista y cada llamada elimina style de los elementos fuera de su lista. Reproduce el caso ejecutando el sanitizador sobre <p style="text-align:center">a</p> y <span style="color:#ff0000;">x</span>. Está terminado cuando esos estilos en línea se conservan, style está permitido en p, h1-h6, div, span, ol, ul y li en una única llamada, y el comportamiento del sanitizador está cubierto por una prueba.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- PHP
- Estrellas
- 47
- Forks
- 35
- Merge medio
- 1 d 2 h
- PR fusionados (30 d)
- 25
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de craftcms/ckeditor
-
repo:ckeditor
Dificultad 1/5 Menos de una hora Aptitud para principiantes 78/100
craftcms/ckeditor#682 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
repo:ckeditor
Dificultad 3/5 1-2 días Aptitud para principiantes 52/100
craftcms/ckeditor#678 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
bug repo:ckeditor
Dificultad 3/5 1-2 días Aptitud para principiantes 40/100
craftcms/ckeditor#665 · 2 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
[6.x]: Esc in a fullscreen CKEditor field closes Preview instead of leaving fullscreenPosiblemente ocupada @i-just la tomó hace 15 días. Abiertobug repo:ckeditor
Dificultad 3/5 1-2 días Aptitud para principiantes 58/100
craftcms/ckeditor#651 · 3 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
bug repo:ckeditor
Dificultad 3/5 1-2 días Aptitud para principiantes 54/100
craftcms/ckeditor#646 · 2 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
Todos los issues de craftcms/ckeditor
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Codeinwp/optimole-wp#1259 ·
Los mantenedores suelen responder en 1 día
-
component/core domain/framework
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 75/100