[5.x]: MySQL DSN in config array bypasses charset
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue nà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
- 62/100
Hướng nghiên cứu
Bắt đầu với DbConfig::init() trong các lớp cấu hình của Craft, hàm này bỏ qua _updateDsn() khi có DSN được cung cấp, nên driver vẫn là null. App::dbConfig() đọc driver từ DSN, vì vậy hãy so sánh hai nơi này. getCharset() nên trả về utf8mb4 cho MySQL sau khi driver đã được xác định. Hoàn thành khi new DbConfig(['dsn' => 'mysql:host=localhost;dbname=example'])->getCharset() trả về utf8mb4 và driver được thiết lập, kèm một unit test bao phủ trường hợp này.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- PHP
- Star
- 3.6k
- Fork
- 714
- Merge trung bình
- 13 giờ 9 phút
- Pull request đã merge (30 ngày)
- 378
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/cms
-
bug repo:cms
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
craftcms/cms#20205 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[6.x]: Element index View menu: sort direction buttons only update after the table has loadedĐang mởbug repo:cms
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
craftcms/cms#20203 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[5.x]: MCP returns `[]` for CKEditor field valuesCó thể đã có người làm @i-just đã nhận 2 ngày trước. Đang mởrepo:cms
craftcms/cms#20404 · 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]: Entry edit page takes ~0.4s longer to first paint for every Matrix blockCó thể đã có người làm @riasvdv đã nhận 2 ngày trước. Đang mởbug repo:cms
craftcms/cms#20401 · 3 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[6.x]: Custom entry source with a single-section condition shows another source's entriesCó thể đã có người làm @brandonkelly đã nhận 3 ngày trước. Đang mởbug
craftcms/cms#20388 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
enhancement priority Sales
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
novalo-dev/Prestashop-MCP-Server#201 ·
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 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Include flows spanning the full report time windowCó thể đã có người làm @somethingwithproof đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
Cacti/plugin_flowview#306 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug origin: upstream priority: low
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
mattytap/Mattytap-Sermons#105 ·
-
priority:low type:bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
crazy-goat/workerman-bundle#1189 ·
Maintainer thường phản hồi trong vòng 1 ngày