[5.x]: MySQL DSN in config array bypasses charset
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 62/100
Línea de trabajo
Empieza con DbConfig::init() en las clases de configuración de Craft, que omite _updateDsn() cuando se proporciona un DSN, por lo que driver se queda en null. App::dbConfig() lee el driver del DSN, así que compara ambos. getCharset() debería devolver utf8mb4 para MySQL una vez resuelto el driver. Está terminado cuando new DbConfig(['dsn' => 'mysql:host=localhost;dbname=example'])->getCharset() devuelve utf8mb4 y el driver está establecido, con una prueba unitaria que cubra este caso.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
What happened?
When a MySQL DSN is supplied through a database config array, DbConfig::$driver remains null. This causes getCharset() to return utf8 instead of normalizing it to utf8mb4.
On MariaDB, creating a table with Craft’s default collation then produces an incompatible combination:
DEFAULT CHARACTER SET = utf8 DEFAULT COLLATE = utf8mb4_unicode_ci
MariaDB rejects this with:
COLLATION 'utf8mb4_unicode_ci' is not valid for CHARACTER SET 'utf8mb3'
Steps to reproduce
This can be reproduced without connecting to a database:
$config = new \craft\config\DbConfig([
'dsn' => 'mysql:host=localhost;dbname=example',
]);
var_dump($config->driver); // null
var_dump($config->getCharset()); // "utf8"
For comparison, explicitly supplying the driver returns the expected charset:
$config = new \craft\config\DbConfig([
'dsn' => 'mysql:host=localhost;dbname=example',
'driver' => 'mysql',
]);
var_dump($config->getCharset()); // "utf8mb4"
Expected behavior
Craft should recognize the MySQL driver from the DSN and normalize the default charset to utf8mb4, consistently with the fluent dsn() method.
Additional information
DbConfig::init() skips _updateDsn() when a DSN is already supplied, leaving the driver unset. Meanwhile, App::dbConfig() reads the driver directly from the DSN, so the connection can work despite the missing configured driver.
Explicitly setting charset to utf8mb4 works around the issue.
Found while investigating Blitz #929.
Tested on Craft 5.11.5.1, but may affect other versions as well.
Craft CMS version
5.11.5.1
PHP version
No response
Operating system and version
No response
Database type and version
No response
Image driver and version
No response
Installed plugins and versions
- Lenguaje dominante
- PHP
- Estrellas
- 3.6k
- Forks
- 712
- Merge medio
- 13 h 5 min
- PR fusionados (30 d)
- 328
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/cms
-
bug repo:cms
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
craftcms/cms#20205 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[6.x]: Element index View menu: sort direction buttons only update after the table has loadedAbiertobug repo:cms
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
craftcms/cms#20203 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[5.x]: Moving an asset with “Replace it” throws TypeError: volumeUid must be of type string, null givenPosiblemente ocupada @i-just la tomó hace 5 días. Abiertobug repo:cms
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
craftcms/cms#20128 · 2 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
bug repo:cms
Dificultad 4/5 1-2 días Aptitud para principiantes 55/100
craftcms/cms#20226 · 1 comentario · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
bug repo:cms
Dificultad 3/5 1-2 días Aptitud para principiantes 65/100
craftcms/cms#20204 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de craftcms/cms
Issues similares
-
Recognise PHP_CodeSniffer (`phpcs`) as a linterPosiblemente ocupada @HarshRajSinghania la tomó hoy. Abiertoenhancement good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
MustacheCase/zanadir#507 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
jwage/phpamqplib-messenger#163 ·
-
Newsletter subscription page logs Undefined array key "nw_error" on every GETPosiblemente ocupada @Codencode la tomó hoy. Abierto
Dificultad 1/5 1-3 horas Aptitud para principiantes 82/100
PrestaShop/ps_emailsubscription#145 · 1 comentario ·
-
PHP 8.5 CURL deprecatedAbierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 82/100