[Bug]: TypeError in ThemingDefaults::getColorPrimary() — preg_match() under PHP 8.4 on unset user primary_color
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
- 77/100
Hướng nghiên cứu
Bắt đầu tại apps/theming/lib/ThemingDefaults.php, khoảng dòng 196, nơi getColorPrimary() đọc primary_color của người dùng và truyền giá trị đó cho preg_match(). Kiểm tra các bài kiểm thử liên quan đến ThemingDefaults và xem getColorBackground() có xử lý đầu vào tương tự không. Xác nhận rằng màu chưa được đặt sẽ quay về giá trị mặc định toàn cục mà không gây lỗi, sau đó chạy các bài kiểm thử theming liên quan.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
⚠️ This issue respects the following points: ⚠️
- This is a bug, not a question or a configuration/webserver/proxy issue.
- This issue is not already reported on Github OR Nextcloud Community Forum (I've searched it).
- Nextcloud Server is up to date. See Maintenance and Release Schedule for supported versions.
- I agree to follow Nextcloud's Code of Conduct.
Bug description
When accessing /apps/files/ (or any page initializing user capabilities/theming) under PHP 8.4+, Nextcloud crashes with a fatal TypeError (HTTP 500) if the logged-in user does not have a custom primary_color configured.
In apps/theming/lib/ThemingDefaults.php line 196-197:
$userPrimaryColor = $this->userConfig->getValueString($user->getUID(), Application::APP_ID, 'primary_color');
if (preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $userPrimaryColor)) {
return $userPrimaryColor;
}
Under PHP 8.4+, preg_match enforces strict types and no longer tolerates non-string types or certain uninitialized proxy representations from getValueString(), throwing:
TypeError: preg_match(): Argument #2 ($subject) must be of type string, string given at /var/www/html/apps/theming/lib/ThemingDefaults.php#197
Steps to reproduce
- Run Nextcloud Server 34.x on PHP 8.4 (e.g. official
nextcloud:34.0.5Apache Docker image). - Log in as an admin or normal user who has never set a custom theming primary color.
- Access
/apps/files/. - The page fails with HTTP 500 Internal Server Error.
Expected behavior
Nextcloud should fall back gracefully to the global system primary color ($defaultColor) without throwing a fatal TypeError.
Nextcloud Server version
34
Operating system
Debian/Ubuntu
PHP engine version
PHP 8.4
Web server
Apache (supported)
Database engine version
PostgreSQL
Is this bug present after an update or on a fresh install?
Updated from a MINOR version (ex. 32.0.1 to 32.0.2)
Are you using the Nextcloud Server Encryption module?
Encryption is Disabled
What user-backends are you using?
- Default user-backend (database)
Nextcloud Logs
{
"reqId": "n6FAHxGdzIB0H4OyzO55",
"level": 3,
"time": "2026-11-04T03:10:52+00:00",
"remoteAddr": "x.x.x.x",
"user": "admin",
"app": "index",
"method": "GET",
"url": "/apps/files/",
"message": "preg_match(): Argument #2 ($subject) must be of type string, string given",
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/27.2 Safari/605.1.15",
"version": "34.0.5.1",
"exception": {
"Exception": "TypeError",
"Message": "preg_match(): Argument #2 ($subject) must be of type string, string given",
"Code": 0,
"Trace": [
{
"function": "preg_match",
"file": "/var/www/html/apps/theming/lib/ThemingDefaults.php",
"line": 197,
"args": ["/^\\#([0-9a-f]{3}|[0-9a-f]{6})$/i", ""]
},
{
"file": "/var/www/html/apps/theming/lib/Capabilities.php",
"line": 88,
"function": "getColorPrimary",
"class": "OCA\\Theming\\ThemingDefaults",
"type": "->"
},
{
"file": "/var/www/html/lib/private/CapabilitiesManager.php",
"line": 60,
"function": "getCapabilities",
"class": "OCA\\Theming\\Capabilities",
"type": "->"
},
{
"file": "/var/www/html/lib/private/Template/JSConfigHelper.php",
"line": 141,
"function": "getCapabilities",
"class": "OC\\CapabilitiesManager",
"type": "->"
},
{
"file": "/var/www/html/lib/private/TemplateLayout.php",
"line": 251,
"function": "getConfig",
"class": "OC\\Template\\JSConfigHelper",
"type": "->"
},
{
"file": "/var/www/html/apps/files/lib/Controller/ViewController.php",
"line": 202,
"function": "dispatchTyped",
"class": "OC\\EventDispatcher\\EventDispatcher",
"type": "->"
}
],
"File": "/var/www/html/apps/theming/lib/ThemingDefaults.php",
"Line": 197
}
}
Suggested Fix
Add defensive type checks and explicit casting in apps/theming/lib/ThemingDefaults.php:
--- a/apps/theming/lib/ThemingDefaults.php
+++ b/apps/theming/lib/ThemingDefaults.php
@@ -194,7 +194,7 @@ class ThemingDefaults extends \OC_Defaults {
// user-defined primary color
if (!empty($user)) {
$userPrimaryColor = $this->userConfig->getValueString($user->getUID(), Application::APP_ID, 'primary_color');
- if (preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $userPrimaryColor)) {
+ if (!empty($userPrimaryColor) && is_string($userPrimaryColor) && preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', (string)$userPrimaryColor)) {
return $userPrimaryColor;
}
}
Similarly for getColorBackground() if applicable.
- Ngôn ngữ chính
- PHP
- Star
- 37.4k
- Fork
- 5.3k
- Merge trung bình
- 2 ngày 5 giờ
- Pull request đã merge (30 ngày)
- 742
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- 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 nextcloud/server
-
[Bug]: DAV Forbidden/InvalidPath responses break on "&" in the message (DOMDocument::createElementNS(): unterminated entity reference)Có thể đã có người làm @th-joerger đã nhận 4 ngày trước. Đang mở0. Needs triage 35-feedback bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/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 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: Files folder-tree API eagerly lists the children of every subfolder at the last requested depth, then discards them (N extra directory listings per request)Có thể đã có người làm @lazerg đã nhận 6 ngày trước. Đang mở0. Needs triage 34-feedback bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
nextcloud/server#65904 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: Contradictory notifications when cancelling welcome email confirmationCó thể đã có người làm @Jashan32 đã nhận 8 ngày trước. Đang mở0. Needs triage 36-feedback bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
Maintainer thường phản hồi trong vòng 1 ngày
-
`OutOfOfficeEventDispatcherJob` is not cleaned up correctlyCó thể đã có người làm @MishowHD đã nhận 7 ngày trước. Đang mở1. to develop bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của nextcloud/server
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
nextcloud/sharelisting#624 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Reusing one Excerpt vnode for desktop and mobile can break redraws when post content changesĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
FriendsOfFlarum/synopsis#16 ·
-
bug javascript
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/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 72/100
simplesamlphp/simplesamlphp#2693 · 1 reaction ·