Formating of error messages will fail for some rules if input is invalid UTF-8
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 68/100
Hướng nghiên cứu
Start by reproducing the Regex rule example with the invalid UTF-8 value "\x80", then trace the error-message formatting path that passes the value to IntlMessageFormatter::format(). Verify the fix by confirming that the result is formatted as "Field not valid." rather than returning the unformatted template, and add coverage for the invalid input if the existing test structure provides a suitable place.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
If a value provided to validation rule is incorrect UTF-8,
then formatting of error messages for some rules will fail and original template message will be returned, without formatting.
For example, rule:
'field' => new Regex(
pattern: '/^abc$/u',
),
input field's value: "\x80" (it is invalid UTF-8)
result error: "{Property} not valid.", instead of "Field not valid."
This happens because for some rules value is passed to formatting along with other parameters:
['property' => ..., 'Property' => ..., 'value' => ...]
IntlMessageFormatter::format() fails to format it and returns false, and not formatted message used as fallback,
it fails because underlying intl ext (ICU library) strictly requires all incoming payload text to be valid UTF-8 or UTF-16
But error message should not be corrupted because of user input, value can be sanitized like this:
mb_substitute_character(0xFFFD);
$clean = mb_convert_encoding($dirty, 'UTF-8', 'UTF-8');
0xFFFD is official Unicode Replacement Character: �
or function from intl ext can be used for same result,
it is better because mb_substitute_character() sets global state
$clean = UConverter::transcode($dirty, 'UTF-8', 'UTF-8');
https://www.php.net/manual/en/uconverter.transcode.php
If the input string contains a sequence of bytes which is not valid in the encoding specified by fromEncoding, they are replaced by Unicode code point U+FFFD (Replacement Character) before converting to toEncoding.
Package version
No response
PHP version
No response
- Ngôn ngữ chính
- PHP
- Star
- 167
- Fork
- 47
- Merge trung bình
- 1 ngày 16 giờ
- Pull request đã merge (30 ngày)
- 4
Chuẩn bị môi trường
- 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 yiisoft/validator
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 65/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
-
Multibyte trim supportĐang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 62/100
-
Make File size validation messages human-readableCó thể làm lại được @samdark đã nhận 119 ngày trước và không có pull request nào đang mở. Đang mởtype:bug
Tất cả issue của yiisoft/validator
Issue tương tự
-
[Sync EN] Fix session read handler docs: false reports a failure, not a missing session (#5902)Đang mởsync-en
Độ khó 2/5 1-2 ngày Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 2 ngày
-
feature-request needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
aws/aws-sdk-php#3365 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 90/100
-
bug status: unverified
Độ 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
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
woocommerce/google-listings-and-ads#3884 ·
Maintainer thường phản hồi trong vòng 1 ngày