[5.x]: MySQL DSN in config array bypasses charset
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 62/100
Direzione di ricerca
Inizia da DbConfig::init() nelle classi di configurazione di Craft, che salta _updateDsn() quando viene fornito un DSN, quindi driver resta null. App::dbConfig() legge il driver dal DSN, quindi confronta i due. getCharset() dovrebbe restituire utf8mb4 per MySQL una volta risolto il driver. È completato quando new DbConfig(['dsn' => 'mysql:host=localhost;dbname=example'])->getCharset() restituisce utf8mb4 e il driver è impostato, con un test unitario che copra questo caso.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- PHP
- Stelle
- 3.6k
- Fork
- 712
- Merge medio
- 12h 40m
- PR unite (30g)
- 344
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di craftcms/cms
-
[6.x]: AI tool-calling check fails with a 400 on Anthropic, so Ask AI can't use Claude modelsApertabug repo:cms
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
craftcms/cms#20266 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug repo:cms
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
craftcms/cms#20205 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
[6.x]: Element index View menu: sort direction buttons only update after the table has loadedApertabug repo:cms
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
craftcms/cms#20203 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
[5.x]: Moving an asset with “Replace it” throws TypeError: volumeUid must be of type string, null givenForse già presa @i-just l’ha presa 6 giorni fa. Apertabug repo:cms
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
craftcms/cms#20128 · 2 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
bug repo:cms
Difficoltà 3/5 1-2 giorni Idoneità per principianti 52/100
craftcms/cms#20271 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di craftcms/cms
Issue simili
-
mobile-app
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
Open-Locker/Open-Locker#352 ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: SCIM Users groups[].value is returned as an integer, causing authentik user discovery to failAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
grokability/snipe-it#20006 ·
I maintainer di solito rispondono entro 1 giorno
-
fixed
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
firefly-iii/firefly-iii#13150 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
type/bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
TYPO3-Solr/ext-solr#4828 ·
I maintainer di solito rispondono entro 5 giorni